Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
16 files changed:
--- /dev/null
+Hello
+Zero: 0
+One: 1 Param1: World
+Zero: 0 Param1: Restored
+Multi line function
+One: 1
--- /dev/null
+f() { echo Hello; }
+g () { echo One: $# Param1: $1; }
+h ( )
+{
+ echo -n 'Multi ' && echo -n 'line '
+ echo function
+ false
+}
+
+f
+echo Zero: $?
+set -- Restored
+{ g World; }
+echo Zero: $? Param1: $1
+( h )
+echo One: $?
--- /dev/null
+First 0
+Second 0
+First 1
+Second 1
+Done
--- /dev/null
+i=0
+while test $i != 2; do
+ f() { echo First $i; }
+ f
+ f() { echo Second $i; }
+ f
+ : $((i++))
+done
+echo Done
--- /dev/null
+One:1
+Zero:0
+One:1
+Five:5
--- /dev/null
+f() { false; return; echo BAD; };
+{ f; echo One:$?; }; echo Zero:$?
+
+f() { false; return; };
+f; echo One:$?
+
+f() { return 5; };
+f; echo Five:$?
--- /dev/null
+func() {
+ eval "echo \"\${val_${1}}\""
+}
+
+val_x=24
+(func x)
+echo Done
--- /dev/null
+1
+2
+3
+1
+2
+3
--- /dev/null
+f() { echo $1; }
+f 1
+
+f() ( echo $1; )
+f 2
+
+f() ( echo $1 )
+f 3
+
+f() for i in 1 2 3; do
+ echo $i
+done
+f
--- /dev/null
+params: a b c
+'f 1 2 3' called
+params: a b c
+'f 1 2 3' called
+params: a b c
--- /dev/null
+
+f() { echo "'f $1 $2 $3' called"; }
+
+set -- a b c
+echo "params: $1 $2 $3"
+f 1 2 3
+echo "params: $1 $2 $3"
+true | f 1 2 3
+echo "params: $1 $2 $3"
--- /dev/null
+z=a
+z=z
+Done
--- /dev/null
+export z=z
+f() { local z=a; env | grep ^z; }
+f
+env | grep ^z
+echo Done
--- /dev/null
+1
+2
+1
+2
+1
+1
+2
+2
+3
+2
+2
+3
+1
+Done
--- /dev/null
+x=1
+f() { echo $x; local x=$((x+1)); echo $x; }
+g() { f; echo $x; f; local x=$((x+1)); f; echo $x; f; }
+f
+g
+echo $x
+echo Done