1 2e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' 3h='##' 4failures='' 5ok='' 6 7testcase() { 8 code="$1" 9 expected="$2" 10 oIFS="$IFS" 11 eval "$code" 12 IFS='|' 13 result="$#|$*" 14 IFS="$oIFS" 15 if [ "x$result" = "x$expected" ]; then 16 ok=x$ok 17 else 18 failures=x$failures 19 echo "For $code, expected $expected actual $result" 20 fi 21} 22 23testcase 'set -- a b' '2|a|b' 24testcase 'set --' '0|' 25testcase 'set -- ${e}' '0|' 26testcase 'set -- "${e}"' '1|' 27 28testcase 'set -- $p' '1|/etc/' 29testcase 'set -- "$p"' '1|/et[c]/' 30testcase 'set -- ${s+$p}' '1|/etc/' 31testcase 'set -- "${s+$p}"' '1|/et[c]/' 32testcase 'set -- ${s+"$p"}' '1|/et[c]/' 33# Dquotes in dquotes is undefined for Bourne shell operators 34#testcase 'set -- "${s+"$p"}"' '1|/et[c]/' 35testcase 'set -- ${e:-$p}' '1|/etc/' 36testcase 'set -- "${e:-$p}"' '1|/et[c]/' 37testcase 'set -- ${e:-"$p"}' '1|/et[c]/' 38# Dquotes in dquotes is undefined for Bourne shell operators 39#testcase 'set -- "${e:-"$p"}"' '1|/et[c]/' 40testcase 'set -- ${e:+"$e"}' '0|' 41testcase 'set -- ${e:+$w"$e"}' '0|' 42testcase 'set -- ${w:+"$w"}' '1|a b c' 43testcase 'set -- ${w:+$w"$w"}' '3|a|b|ca b c' 44 45testcase 'set -- "${s+a b}"' '1|a b' 46testcase 'set -- "${e:-a b}"' '1|a b' 47testcase 'set -- ${e:-\}}' '1|}' 48testcase 'set -- ${e:+{}}' '1|}' 49testcase 'set -- "${e:+{}}"' '1|}' 50 51testcase 'set -- ${e+x}${e+x}' '1|xx' 52testcase 'set -- "${e+x}"${e+x}' '1|xx' 53testcase 'set -- ${e+x}"${e+x}"' '1|xx' 54testcase 'set -- "${e+x}${e+x}"' '1|xx' 55testcase 'set -- "${e+x}""${e+x}"' '1|xx' 56 57testcase 'set -- ${e:-${e:-$p}}' '1|/etc/' 58testcase 'set -- "${e:-${e:-$p}}"' '1|/et[c]/' 59testcase 'set -- ${e:-"${e:-$p}"}' '1|/et[c]/' 60testcase 'set -- ${e:-${e:-"$p"}}' '1|/et[c]/' 61testcase 'set -- ${e:-${e:-${e:-$w}}}' '3|a|b|c' 62testcase 'set -- ${e:-${e:-${e:-"$w"}}}' '1|a b c' 63testcase 'set -- ${e:-${e:-"${e:-$w}"}}' '1|a b c' 64testcase 'set -- ${e:-"${e:-${e:-$w}}"}' '1|a b c' 65testcase 'set -- "${e:-${e:-${e:-$w}}}"' '1|a b c' 66 67testcase 'shift $#; set -- ${1+"$@"}' '0|' 68testcase 'set -- ""; set -- ${1+"$@"}' '1|' 69testcase 'set -- "" a; set -- ${1+"$@"}' '2||a' 70testcase 'set -- a ""; set -- ${1+"$@"}' '2|a|' 71testcase 'set -- a b; set -- ${1+"$@"}' '2|a|b' 72testcase 'set -- a\ b; set -- ${1+"$@"}' '1|a b' 73testcase 'set -- " " ""; set -- ${1+"$@"}' '2| |' 74 75test "x$failures" = x 76