# tilde-p.sh: test of tilde expansion for any POSIX-compliant shell posix="true" setup -d ( setup 'HOME=/foo/bar' test_oE 'quoted tilde is not expanded (in command word)' bracket \~ '~' "~" ~\/ __IN__ [~][~][~][~/] __OUT__ test_oE 'unnamed tilde expansion, end of word' bracket ~ HOME=/tilde/expansion bracket ~ __IN__ [/foo/bar] [/tilde/expansion] __OUT__ test_oE 'unnamed tilde expansion, followed by slash' bracket ~/ ~/baz HOME=/tilde/expansion bracket ~/ ~/slash __IN__ [/foo/bar/][/foo/bar/baz] [/tilde/expansion/][/tilde/expansion/slash] __OUT__ test_OE -e 0 'exit status of successful unnamed tilde expansion (in command word)' : ~ ~/ ~/foo __IN__ test_oE 'quoted tilde is not expanded in assignment' a=\~ b='~' c="~" d=~\/ bracket "$a" "$b" "$c" "$d" __IN__ [~][~][~][~/] __OUT__ test_oE 'unnamed tilde expansion in assignment, end of word' a=~ HOME=/tilde/expansion b=~ bracket "$a" "$b" __IN__ [/foo/bar][/tilde/expansion] __OUT__ test_oE 'unnamed tilde expansion in assignment, followed by slash' a=~/ b=~/baz HOME=/tilde/expansion c=~/ d=~/slash bracket "$a" "$b" "$c" "$d" __IN__ [/foo/bar/][/foo/bar/baz][/tilde/expansion/][/tilde/expansion/slash] __OUT__ test_oE 'unnamed tilde expansion in assignment, followed by colon' a=~: b=~:baz HOME=/tilde/expansion c=~: d=~:colon bracket "$a" "$b" "$c" "$d" __IN__ [/foo/bar:][/foo/bar:baz][/tilde/expansion:][/tilde/expansion:colon] __OUT__ test_oE -e 0 'unnamed tilde expansion in assignment, following colon' a=:~ b=baz:~ HOME=/tilde/expansion c=:~ d=colon:~ bracket "$a" "$b" "$c" "$d" __IN__ [:/foo/bar][baz:/foo/bar][:/tilde/expansion][colon:/tilde/expansion] __OUT__ test_oE -e 0 'unnamed tilde expansion in assignment, between colon' a=:~: b=baz:~:baz HOME=/tilde/expansion c=:~: d=colon:~:colon bracket "$a" "$b" "$c" "$d" __IN__ [:/foo/bar:][baz:/foo/bar:baz][:/tilde/expansion:][colon:/tilde/expansion:colon] __OUT__ test_oE -e 0 'many unnamed tilde expansions in assignment' a=~:x:~/y:~:~ bracket "$a" __IN__ [/foo/bar:x:/foo/bar/y:/foo/bar:/foo/bar] __OUT__ test_OE -e 0 'exit status of successful unnamed tilde expansion in assignment' a=~:x:~/y:~:~ __IN__ ) ( if ! { LOGNAME="$(logname)" && export LOGNAME; } then skip="true" elif # The current user's name has to be portable. printf '%s\n' "$LOGNAME" | \ grep -q '[^0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-]' then skip="true" elif # Tests of named tilde expansions depend on the home directory of the # current user. ! { HOME="$(eval printf \'%s\\\n\' \~$LOGNAME)" && export HOME && [ "$HOME" ]; } then skip="true" fi if "${skip:-false}"; then LOGNAME= HOME= fi testcase "$LINENO" 'tilde with quoted name is not expanded (in command word)' \ 3<<__IN__ 4<<__OUT__ 5