tilde1.0 revision 303975
1# $FreeBSD: releng/11.0/bin/sh/tests/expansion/tilde1.0 206149 2010-04-03 21:56:24Z jilles $ 2 3HOME=/tmp 4roothome=~root 5if [ "$roothome" = "~root" ]; then 6 echo "~root is not expanded!" 7 exit 2 8fi 9 10testcase() { 11 code="$1" 12 expected="$2" 13 oIFS="$IFS" 14 eval "$code" 15 IFS='|' 16 result="$#|$*" 17 IFS="$oIFS" 18 if [ "x$result" = "x$expected" ]; then 19 ok=x$ok 20 else 21 failures=x$failures 22 echo "For $code, expected $expected actual $result" 23 fi 24} 25 26testcase 'set -- ~' '1|/tmp' 27testcase 'set -- ~/foo' '1|/tmp/foo' 28testcase 'set -- x~' '1|x~' 29testcase 'set -- ~root' "1|$roothome" 30h=~ 31testcase 'set -- "$h"' '1|/tmp' 32ooIFS=$IFS 33IFS=m 34testcase 'set -- ~' '1|/tmp' 35testcase 'set -- ~/foo' '1|/tmp/foo' 36testcase 'set -- $h' '2|/t|p' 37IFS=$ooIFS 38t=\~ 39testcase 'set -- $t' '1|~' 40r=$(cat <<EOF 41~ 42EOF 43) 44testcase 'set -- $r' '1|~' 45r=$(cat <<EOF 46${t+~} 47EOF 48) 49testcase 'set -- $r' '1|~' 50r=$(cat <<EOF 51${t+~/.} 52EOF 53) 54testcase 'set -- $r' '1|~/.' 55 56test "x$failures" = x 57