| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # ref-params.sh: Dereferencing a parameter passed to a function. |
| 3 | # (Complex Example) |
| 4 | |
| 5 | ITERATIONS=3 # How many times to get input. |
| 6 | icount=1 |
| 7 | |
| 8 | my_readscip-shell shell abs-guide 10-4 my_read(). () { |
| 9 | # Called with my_read varname, |
| 10 | #+ outputs the previous value between brackets as the default value, |
| 11 | #+ then asks for a new value. |
| 12 | |
| 13 | local local_var |
| 14 | |
| 15 | echoscip-shell system . . echo. -n "Enter a value " |
| 16 | eval 'echo -n "[$'$1'] "' # Previous value. |
| 17 | # eval echo -n "[\$$1] " # Easier to understand, |
| 18 | #+ but loses trailing space in user prompt. |
| 19 | read local_var |
| 20 | [scip-shell system . . `[`. -n "$local_var" ] && eval $1=\$local_var |
| 21 | |
| 22 | # "And-list": if "local_var" then set "$1" to its value. |
| 23 | } |
| 24 | |
| 25 | echoscip-shell system . . echo. |
| 26 | |
| 27 | while [scip-shell system . . `[`. "$icount" -le "$ITERATIONS" ] |
| 28 | do |
| 29 | my_readscip-shell shell abs-guide 10-4 my_read(). var |
| 30 | echoscip-shell system . . echo. "Entry #$icount = $var" |
| 31 | let "icount += 1" |
| 32 | echoscip-shell system . . echo. |
| 33 | done |
| 34 | |
| 35 | |
| 36 | # Thanks to Stephane Chazelas for providing this instructive example. |
| 37 | |
| 38 | exit 0 |