1# This is really a test for outqstr(), which is readily accessible via trap. 2 3runtest() 4{ 5 teststring=$1 6 trap -- "$teststring" USR1 7 traps=$(trap) 8 if [ "$teststring" != "-" ] && [ -z "$traps" ]; then 9 # One possible reading of POSIX requires the above to return an 10 # empty string because backquote commands are executed in a 11 # subshell and subshells shall reset traps. However, an example 12 # in the normative description of the trap builtin shows the 13 # same usage as here, it is useful and our /bin/sh allows it. 14 echo '$(trap) is broken' 15 exit 1 16 fi 17 trap - USR1 18 eval "$traps" 19 traps2=$(trap) 20 if [ "$traps" != "$traps2" ]; then 21 echo "Mismatch for '$teststring'" 22 exit 1 23 fi 24} 25 26runtest 'echo' 27runtest 'echo hi' 28runtest "'echo' 'hi'" 29runtest '"echo" $PATH' 30runtest '\echo "$PATH"' 31runtest ' 0' 32runtest '0 ' 33runtest ' 1' 34runtest '1 ' 35i=1 36while [ $i -le 127 ]; do 37 c=$(printf \\"$(printf %o $i)") 38 if [ $i -lt 48 ] || [ $i -gt 57 ]; then 39 runtest "$c" 40 fi 41 runtest " $c$c" 42 runtest "a$c" 43 i=$((i+1)) 44done 45IFS=, 46runtest ' ' 47runtest ',' 48unset IFS 49runtest ' ' 50 51exit 0 52