This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1.) There is not try/catch in bash, but you can use the || and && operands as semi-equivalents. | |
| # Think of || as "or". | |
| # If command1 fails, then run command2: | |
| $ command1 || command2 | |
| # Think of && as "and". | |
| # If command1 succeeds, then run command2: | |
| $ command1 && command2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # These | |
| $ FOO="abc123" | |
| $ echo $FOO | |
| abc123 | |
| # Get the variable length in chars: ${#FOO} | |
| $ echo ${#FOO} | |
| 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ python | |
| Python 3.7.2 (default, Dec 27 2018, 07:35:06) | |
| [Clang 10.0.0 (clang-1000.11.45.5)] on darwin | |
| Type "help", "copyright", "credits" or "license" for more information. | |
| >>> def hello(fruit_basket): | |
| ... for i in fruit_basket: | |
| ... print(f"-- {i}") | |
| ... | |
| >>> stuff = ( "apple", "carrot", "hamster") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PS> cat .\pets.txt | |
| dog,bowser,5 | |
| cat,mimi,4 | |
| snake,mr slithers,18 | |
| PS> get-content "pets.txt" | foreach-object { | |
| $data = $_ -split "," | |
| "{1} is a {0} who is {2} years old" -f $data[0],$data[1],$data[2] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PS1> Get-Content foo.txt | |
| dog | |
| cat | |
| bird | |
| fish | |
| chicken | |
| duck | |
| giraffe | |
| PS1> Get-Content foo.txt | %{$_ -replace "duck", "fruit"} |
NewerOlder