Debian Codegraph @

arglist.sh

raw symbols SCIP
1 #!/bin/bash
2 # arglist.sh
3 # Invoke this script with several arguments, such as "one two three" ...
4
5 E_BADARGS=85
6
7 if [ ! -n "$1" ]
8 then
9 echo "Usage: `basename $0` argument1 argument2 etc."
10 exit $E_BADARGS
11 fi
12
13 echo
14
15 index=1 # Initialize count.
16
17 echo "Listing args with \"\$*\":"
18 for arg in "$*" # Doesn't work properly if "$*" isn't quoted.
19 do
20 echo "Arg #$index = $arg"
21 let "index+=1"
22 done # $* sees all arguments as single word.
23 echo "Entire arg list seen as single word."
24
25 echo
26
27 index=1 # Reset count.
28 # What happens if you forget to do this?
29
30 echo "Listing args with \"\$@\":"
31 for arg in "$@"
32 do
33 echo "Arg #$index = $arg"
34 let "index+=1"
35 done # $@ sees arguments as separate words.
36 echo "Arg list seen as separate words."
37
38 echo
39
40 index=1 # Reset count.
41
42 echo "Listing args with \$* (unquoted):"
43 for arg in $*
44 do
45 echo "Arg #$index = $arg"
46 let "index+=1"
47 done # Unquoted $* sees arguments as separate words.
48 echo "Arg list seen as separate words."
49
50 exit 0