| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # echo-params.sh |
| 3 | |
| 4 | # Call this script with a few command-line parameters. |
| 5 | # For example: |
| 6 | # sh echo-params.sh first second third fourth fifth |
| 7 | |
| 8 | params=$# # Number of command-line parameters. |
| 9 | param=1 # Start at first command-line param. |
| 10 | |
| 11 | while [scip-shell system . . `[`. "$param" -le "$params" ] |
| 12 | do |
| 13 | echoscip-shell system . . echo. -n "Command-line parameter " |
| 14 | echoscip-shell system . . echo. -n \$$param # Gives only the *name* of variable. |
| 15 | # ^^^ # $1, $2, $3, etc. |
| 16 | # Why? |
| 17 | # \$ escapes the first "$" |
| 18 | #+ so it echoes literally, |
| 19 | #+ and $param dereferences "$param" . . . |
| 20 | #+ . . . as expected. |
| 21 | echoscip-shell system . . echo. -n " = " |
| 22 | eval echo \$$param # Gives the *value* of variable. |
| 23 | # ^^^^ ^^^ # The "eval" forces the *evaluation* |
| 24 | #+ of \$$ |
| 25 | #+ as an indirect variable reference. |
| 26 | |
| 27 | (( param ++ )) # On to the next. |
| 28 | done |
| 29 | |
| 30 | exit $? |
| 31 | |
| 32 | # ================================================= |
| 33 | |
| 34 | $ sh echo-params.sh first second third fourth fifth |
| 35 | Command-line parameter $1 = first |
| 36 | Command-line parameter $2 = second |
| 37 | Command-line parameter $3 = third |
| 38 | Command-line parameter $4 = fourth |
| 39 | Command-line parameter $5 = fifth |