########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2010 AT&T Intellectual Property #
# and is licensed under the #
# Common Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
cat > $f <<!
!
if [[ $(<$f) != 'hello world' ]]
then err_exit "'hello world' here doc not working"
fi
cat > $g <<\!
!
cat > $g <<- !
!
cat > $g <<- \!
!
x=hello
cat > $g <<!
$x world
!
cat > $g <<!
!
cat > $f <<\!!
!@#$%%^^&*()_+~"::~;'`<>?/.,{}[]
!!
if [[ $(<$f) != '!@#$%%^^&*()_+~"::~;'\''`<>?/.,{}[]' ]]
then err_exit "'hello world' here doc not working"
fi
cat > $g <<!!
!@#\$%%^^&*()_+~"::~;'\`<>?/.,{}[]
!!
exec 3<<!
!
if [[ $(<&3) != ' foo' ]]
then err_exit "leading tabs stripped with <<!"
fi
$SHELL -c "
abc
EOF
cat >$g << :
:
:
x=$(print $( cat <<HUP
hello
HUP
)
)
if [[ $x != hello ]]
then err_exit "here doc inside command sub not working"
fi
y=$(cat <<!
${x:+${x}}
!
)
if [[ $y != "${x:+${x}}" ]]
then err_exit '${x:+${x}} not working in here document'
fi
$SHELL -c '
x=0
while (( x < 100 ))
do ((x = x+1))
cat << EOF
EOF
done
{
print 'builtin -d cat
cat <<- EOF'
for ((i=0; i < 100; i++))
do print XXXXXXXXXXXXXXXXXXXX
done
print ' XXX$(date)XXXX
EOF'
} > $f
chmod +x "$f"
$0
!
)
$SHELL -c 'x=$(
cat << EOF
!) != :hi: ]]
then err_exit '$IFS unset by command substitution in here docs'
fi
else err_exit '<<< syntax not supported'
fi
if [[ $(cat << EOF #testing
#abc
abc
EOF) != $'#abc\nabc' ]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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
EOF
print -r -- "$(foobar)"
!!!!
if [[ $($SHELL "$f") != foobar ]]
then err_exit 'here document with stdin closed failed'
fi
printf $'cat <<# \\!!!\n\thello\n\t\tworld\n!!!' > $f
[[ $($SHELL "$f") == $'hello\n\tworld' ]] || err_exit "<<# not working for quoted here documents"
printf $'w=world;cat <<# !!!\n\thello\n\t\t$w\n!!!' > $f
[[ $($SHELL "$f") == $'hello\n\tworld' ]] || err_exit "<<# not working for non-quoted here documents"
[[ $( $SHELL <<- \++++
S=( typeset a )
function S.a.get
{
.sh.value=$__a
}
__a=1234
cat <<-EOF
${S.a}
EOF
++++
) == 1234 ]] 2> /dev/null || err_exit 'here document with get discipline failed'
[[ $($SHELL -c 'g(){ print ok;}; cat <<- EOF
${ g;}
EOF
' 2> /dev/null) == ok ]] || err_exit '${ command;} not working in heredoc'
script=$f
{
for ((i=0; i < 406; i++))
do print ': 23456789012345678'
done
print : 123456789123
cat <<- \EOF
eval "$(
{ cat ; } <<MARKER
print hello
MARKER
)"
EOF
} > $script
[[ $($SHELL $script) == hello ]] 2> /dev/null || err_exit 'heredoc embeded in command substitution fails at buffer boundary'
\
abc
EOF)
[[ $got == abc ]] || err_exit 'line continuation at start of buffer not working'
exit $((Errors))