| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | dir1=/usr/localscip-shell filesystem . . `/usr/local`. |
| 4 | dir2=/var/spoolscip-shell filesystem . . `/var/spool`. |
| 5 | |
| 6 | pushd $dir1 |
| 7 | # Will do an automatic 'dirs' (list directory stack to stdout). |
| 8 | echoscip-shell system . . echo. "Now in directory `pwdscip-shell system . . pwd.`." # Uses back-quoted 'pwd'. |
| 9 | |
| 10 | # Now, do some stuff in directory 'dir1'. |
| 11 | pushd $dir2 |
| 12 | echoscip-shell system . . echo. "Now in directory `pwdscip-shell system . . pwd.`." |
| 13 | |
| 14 | # Now, do some stuff in directory 'dir2'. |
| 15 | echoscip-shell system . . echo. "The top entry in the DIRSTACK array is $DIRSTACK." |
| 16 | popd |
| 17 | echoscip-shell system . . echo. "Now back in directory `pwdscip-shell system . . pwd.`." |
| 18 | |
| 19 | # Now, do some more stuff in directory 'dir1'. |
| 20 | popd |
| 21 | echoscip-shell system . . echo. "Now back in original working directory `pwdscip-shell system . . pwd.`." |
| 22 | |
| 23 | exit 0 |
| 24 | |
| 25 | # What happens if you don't 'popd' -- then exit the script? |
| 26 | # Which directory do you end up in? Why? |