January 2004
Intermediate to advanced
368 pages
7h 25m
English
Many of the scripts in this chapter have been written as functions rather than as stand-alone scripts so that they can be easily and gracefully incorporated into other scripts without incurring the overhead of making system calls. While there's no #include feature in a shell script, as there is in C, there is a tremendously important capability called sourcing a file that serves the same purpose.
To see why this is important, let's consider the alternative. If you invoke a shell script within a shell, by default that script is run within its own subshell. You can immediately prove this experimentally:
$ cat tinyscript.sh test=2 $ test=1 $ tinyscript.sh $ echo $test 1
Because this script changed the value ...
Read now
Unlock full access