# cmdsub-p.sh: test of command substitution for any POSIX-compliant shell posix="true" > dummyfile setup -d test_oE -e 0 'result of command substitution' a=$(echo a) && bracket $a`echo b` __IN__ [ab] __OUT__ test_oE 'command substitution executes in subshell' a=a b=$(a=x; echo b) bracket $a$b __IN__ [ab] __OUT__ test_oE 'trailing newlines are removed' a=$(printf 'x\ny') b=$(printf 'x\ny\n') c=$(printf 'x\n\ny\n\n\n\n') bracket "$a" "$b" "$c" __IN__ [x y][x y][x y] __OUT__ test_oE 'stdin is not redirected' echo a | echo $(cat) __IN__ a __OUT__ test_oe -e 0 'stderr is not redirected' bracket "$(echo x >&2)" __IN__ [] __OUT__ x __ERR__ test_oE 'field splitting on result of command substitution' bracket $(printf 'a\n\nb') __IN__ [a][b] __OUT__ test_oE 'backslash in backquotes / nested backquotes' echoraw `echoraw \`echoraw x\`` echoraw `echoraw '\$y'` echoraw `printf '%s\n' \\\\` __IN__ x $y \ __OUT__ test_oE 'quotations in backquotes' echoraw `echoraw "a"'b'` echoraw `echoraw \$ "\$" '\$'` echoraw `echoraw \\\\ "\\\\" '\\\\'` echoraw `echoraw \" "\"" '\"'` echoraw `echoraw \' "\'"` echoraw `echoraw \`echo a\` "\`echo b\`" '\`echo c\`'` __IN__ ab $ $ $ \ \ \\ " " \" ' \' a b `echo c` __OUT__ test_oE 'quotations in backquotes in double quotes' echoraw "`echoraw "a"'b'`" echoraw "`echoraw \$ "\$" '\$'`" echoraw "`echoraw \\\\ "\\\\" '\\\\'`" echoraw "`echoraw \"1\"`" echoraw "`echoraw \'2\'`" echoraw "`echoraw \`echo a\` "\`echo b\`" '\`echo c\`'`" __IN__ ab $ $ $ \ \ \\ 1 '2' a b `echo c` __OUT__ test_oE 'quotations in backquotes in here-document' cat <