| 1 | #!/bin/bashscip-shell filesystem . . `/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 [scip-shell system . . `[`. ! -n "$1" ] |
| 8 | then |
| 9 | echoscip-shell system . . echo. "Usage: `basenamescip-shell system . . basename. $0` argument1 argument2 etc." |
| 10 | exit $E_BADARGS |
| 11 | fi |
| 12 | |
| 13 | echoscip-shell system . . echo. |
| 14 | |
| 15 | index=1 # Initialize count. |
| 16 | |
| 17 | echoscip-shell system . . echo. "Listing args with \"\$*\":" |
| 18 | for arg in "$*" # Doesn't work properly if "$*" isn't quoted. |
| 19 | do |
| 20 | echoscip-shell system . . echo. "Arg #$index = $arg" |
| 21 | let "index+=1" |
| 22 | done # $* sees all arguments as single word. |
| 23 | echoscip-shell system . . echo. "Entire arg list seen as single word." |
| 24 | |
| 25 | echoscip-shell system . . echo. |
| 26 | |
| 27 | index=1 # Reset count. |
| 28 | # What happens if you forget to do this? |
| 29 | |
| 30 | echoscip-shell system . . echo. "Listing args with \"\$@\":" |
| 31 | for arg in "$@" |
| 32 | do |
| 33 | echoscip-shell system . . echo. "Arg #$index = $arg" |
| 34 | let "index+=1" |
| 35 | done # $@ sees arguments as separate words. |
| 36 | echoscip-shell system . . echo. "Arg list seen as separate words." |
| 37 | |
| 38 | echoscip-shell system . . echo. |
| 39 | |
| 40 | index=1 # Reset count. |
| 41 | |
| 42 | echoscip-shell system . . echo. "Listing args with \$* (unquoted):" |
| 43 | for arg in $* |
| 44 | do |
| 45 | echoscip-shell system . . echo. "Arg #$index = $arg" |
| 46 | let "index+=1" |
| 47 | done # Unquoted $* sees arguments as separate words. |
| 48 | echoscip-shell system . . echo. "Arg list seen as separate words." |
| 49 | |
| 50 | exit 0 |