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
| #!/bin/bash | |
| # Bash has "dynamic" scoping: | |
| # Variable lookups occur in the scope where a function is CALLED | |
| animal="dog" | |
| function get_animal() { | |
| echo "I have a ${animal}" | |
| } | |
| function mypet() { |
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
| #!/bin/bash | |
| # The -e or --errexit shell option causes the shell to exit immediately when | |
| # a command returns a non-zero status (with some exceptions). An ERR trap gets | |
| # executed before the shell exits | |
| set -o errexit | |
| trap 'echo trapped!' ERR | |
| # This command will have a non-zero exit status, since a standard user has no | |
| # permission to enter the /root directory. Because of the error the trap will |
NewerOlder