10.10 Simulated Bourne Shell Functions and AliasesIf you have a Bourne shell with no functions (10.9 ) or aliases (10.2 ) , you can do a lot of the same things with shell variables and the eval (8.10 ) command. Let's look at an example. First, here's a shell function named scp (safe copy). If the destination file exists and isn't empty, the function prints an error message instead of copying:
If you use the same scp twice, the first time you'll make bfile . The second time you try, you see the error: $ Here's the same scp -stored in a shell variable instead of a function: scp=' if test ! -s "$2" then cp "$1" "$2" else echo "scp: cannot copy $1: $2 exists" fi ' Because this fake function uses shell parameters, you have to add an extra step: setting the parameters. Simpler functions are easier to use:
- |
|