1 2HOME=/tmp 3roothome=~root 4if [ "$roothome" = "~root" ]; then 5 echo "~root is not expanded!" 6 exit 2 7fi 8 9testcase() { 10 code="$1" 11 expected="$2" 12 oIFS="$IFS" 13 eval "$code" 14 IFS='|' 15 result="$#|$*" 16 IFS="$oIFS" 17 if [ "x$result" = "x$expected" ]; then 18 ok=x$ok 19 else 20 failures=x$failures 21 echo "For $code, expected $expected actual $result" 22 fi 23} 24 25testcase 'set -- ${$+~}' '1|/tmp' 26testcase 'set -- ${$+~/}' '1|/tmp/' 27testcase 'set -- ${$+~/foo}' '1|/tmp/foo' 28testcase 'set -- ${$+x~}' '1|x~' 29testcase 'set -- ${$+~root}' "1|$roothome" 30testcase 'set -- ${$+"~"}' '1|~' 31testcase 'set -- ${$+"~/"}' '1|~/' 32testcase 'set -- ${$+"~/foo"}' '1|~/foo' 33testcase 'set -- ${$+"x~"}' '1|x~' 34testcase 'set -- ${$+"~root"}' "1|~root" 35testcase 'set -- "${$+~}"' '1|~' 36testcase 'set -- "${$+~/}"' '1|~/' 37testcase 'set -- "${$+~/foo}"' '1|~/foo' 38testcase 'set -- "${$+x~}"' '1|x~' 39testcase 'set -- "${$+~root}"' "1|~root" 40testcase 'set -- ${HOME#~}' '0|' 41h=~ 42testcase 'set -- "$h"' '1|/tmp' 43f=~/foo 44testcase 'set -- "$f"' '1|/tmp/foo' 45testcase 'set -- ${f#~}' '1|/foo' 46testcase 'set -- ${f#~/}' '1|foo' 47 48ooIFS=$IFS 49IFS=m 50testcase 'set -- ${$+~}' '1|/tmp' 51testcase 'set -- ${$+~/foo}' '1|/tmp/foo' 52testcase 'set -- ${$+$h}' '2|/t|p' 53testcase 'set -- ${HOME#~}' '0|' 54IFS=$ooIFS 55 56t=\~ 57testcase 'set -- ${$+$t}' '1|~' 58r=$(cat <<EOF 59${HOME#~} 60EOF 61) 62testcase 'set -- $r' '0|' 63r=$(cat <<EOF 64${HOME#'~'} 65EOF 66) 67testcase 'set -- $r' '1|/tmp' 68r=$(cat <<EOF 69${t#'~'} 70EOF 71) 72testcase 'set -- $r' '0|' 73r=$(cat <<EOF 74${roothome#~root} 75EOF 76) 77testcase 'set -- $r' '0|' 78r=$(cat <<EOF 79${f#~} 80EOF 81) 82testcase 'set -- $r' '1|/foo' 83r=$(cat <<EOF 84${f#~/} 85EOF 86) 87testcase 'set -- $r' '1|foo' 88 89test "x$failures" = x 90