Debian Codegraph @

ref-params.sh

raw symbols SCIP
1 #!/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_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 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 [ -n "$local_var" ] && eval $1=\$local_var
21
22 # "And-list": if "local_var" then set "$1" to its value.
23 }
24
25 echo
26
27 while [ "$icount" -le "$ITERATIONS" ]
28 do
29 my_read var
30 echo "Entry #$icount = $var"
31 let "icount += 1"
32 echo
33 done
34
35
36 # Thanks to Stephane Chazelas for providing this instructive example.
37
38 exit 0