| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # Hunting variables with a trap. |
| 3 | |
| 4 | trap 'echo Variable Listing --- a = $a b = $b' EXIT |
| 5 | # EXIT is the name of the signal generated upon exit from a script. |
| 6 | # |
| 7 | # The command specified by the "trap" doesn't execute until |
| 8 | #+ the appropriate signal is sent. |
| 9 | |
| 10 | echoscip-shell system . . echo. "This prints before the \"trap\" --" |
| 11 | echoscip-shell system . . echo. "even though the script sees the \"trap\" first." |
| 12 | echoscip-shell system . . echo. |
| 13 | |
| 14 | a=39 |
| 15 | |
| 16 | b=36 |
| 17 | |
| 18 | exit 0 |
| 19 | # Note that commenting out the 'exit' command makes no difference, |
| 20 | #+ since the script exits in any case after running out of commands. |