xref: /freebsd/bin/sh/tests/expansion/cmdsubst24.0 (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1# POSIX leaves the effect of NUL bytes in command substitution output
2# unspecified but we have always discarded them.
3
4failures=0
5
6check() {
7	if [ "$2" != "$3" ]; then
8		printf "Failed at line %s: got \"%s\" expected \"%s\"\n" "$1" "$2" "$3"
9		: $((failures += 1))
10	fi
11}
12
13fmt='\0a\0 \0b\0c d\0'
14assign_builtin=$(printf "$fmt")
15check "$LINENO" "$assign_builtin" "a bc d"
16assign_pipeline=$(printf "$fmt" | cat)
17check "$LINENO" "$assign_pipeline" "a bc d"
18set -- $(printf "$fmt") $(printf "$fmt" | cat) "$(printf "$fmt")" "$(printf "$fmt" | cat)"
19IFS=@
20splits="$*"
21check "$LINENO" "$splits" "a@bc@d@a@bc@d@a bc d@a bc d"
22
23[ "$failures" = 0 ]
24