December 1999
Beginner
528 pages
11h 10m
English
When parameters are passed to a script a method is required that will help us shift through each parameter so that we can process the options. This is what the shift command does. It shifts positional arguments one place to the left. To explain how this works let’s first look at a simple script using a while loop to echo out all the arguments passed to a script.
$ pg opt2
#!/bin/sh
# opt2
loop=0
while [ $# -ne 0 ] # while there are still arguments
do
echo $1
done You may think that the script above will process until there are no more arguments left on the command line. Wrong, I’m afraid. Because there is no way to shift to the next parameter inside the script, it will just keep echoing out the first argument. Here’s ...
Read now
Unlock full access