quoting2.sh revision 7c2fbfb345896881c631598ee3852ce9ce33fb07
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin########################################################################
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# This software is part of the ast package #
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# Copyright (c) 1982-2008 AT&T Intellectual Property #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# and is licensed under the #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Common Public License, Version 1.0 #
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# by AT&T Intellectual Property #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# A copy of the License is available at #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Information and Software Systems Research #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# AT&T Research #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Florham Park NJ #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# David Korn <dgk@research.att.com> #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin########################################################################
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "single quotes not the same as double quotes"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinx='hi there'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $x != 'hi there' ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $x != "hi there" ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ \a\b\c\*\|\"\ \\ != 'abc*|" \' ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit " \\ differs from '' "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(print -r - "$(print -r - 'abc*|" \')") != 'abc*|" \' ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "nested \$(print -r - '') differs from ''"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ "$(print -r - $(print -r - 'abc*|" \'))" != 'abc*|" \' ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "\"nested \$(print -r - '')\" differs from ''"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(print -r - "$(print -r - 'abc*|" \')") != 'abc*|" \' ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "nested \"\$(print -r - '')\" differs from ''"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "\${x-\$(print -r - '}')} differs from ''"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinx=$((echo foo)|(cat))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $x != foo ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "((cmd)|(cmd)) failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinx=$(print -r -- "\"$HOME\"")
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "nested double quotes failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin: ${z="a{b}c"}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin: "${z="a{b}c"}"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '$(print -r -- "a\*b$x") differs from a\*b'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- ${x+foo bar bam}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# !=3 ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '${x+foo bar bam} does not yield three arguments'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- ${x+foo "bar bam"}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# !=2 ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '${x+foo "bar bam"} does not yield two arguments'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# !=2 ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '${x+foo '\''bar bam'\''} does not yield two arguments'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- ${x+foo $x bam}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# !=3 ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '${x+foo $x bam} does not yield three arguments'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- ${x+foo "$x" bam}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# !=3 ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '${x+foo "$x" bam} does not yield three arguments'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- ${x+"foo $x bam"}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# !=1 ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '${x+"foo $x bam"} does not yield one argument'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- "${x+foo $x bam}"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# !=1 ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '"${x+foo $x bam}" does not yield one argument'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- ${x+foo "$x "bam}
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# !=2 ))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '${x+foo "$x "bam} does not yield two arguments'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $x != 'ab$' ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'line continuation in double strings not working'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'line continuation in expanded double strings not working'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# The following caused a syntax error on earlier versions
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfoo=foo x=-
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ `eval print \\${foo$x}` != foo* ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ "`eval print \\${foo$x}`" != foo* ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif ( [[ $() != '' ]] )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinset -- $( IFS=:; print $x)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (( $# != 3))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'IFS not working correctly with command substitution'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin$SHELL -n 2> /dev/null << \! || err_exit '$(...) bug with ( in comment'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin # ( this line is a bug fix
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfor j in glob noglob
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin do eval [[ '$('print -r -- \'$i\'\$x')' != "'$i'" ]] && err_exit "quoting of $i\$x with $j enabled failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin eval [[ '$('print -r -- \'$i\'\${x%*}')' != "'$i'" ]] && err_exit "quoting of $i\${x%*} with $j enabled failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if [[ $j == noglob ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then eval [[ '$('print -r -- \'$i\'\${x:-*}')' != "'$i''*'" ]] && err_exit "quoting of $i\${x:-*} with $j enabled failed"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ "${foo}$" == 'foo$' ]] || err_exit 'foo=foo;"${foo}$" != foo$'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ "${foo}${foo}$" == 'foofoo$' ]] || err_exit 'foo=foo;"${foo}${foo}$" != foofoo$'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$foo" == ~(Elr)(\\\$|#)\ ]] || err_exit $'\'$ \' not matching RE \\\\\\$|#\''
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$foo" == ~(Elr)('\$'|#)\ ]] || err_exit $'\'$ \' not matching RE \'\\$\'|#\''
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$foo" == ~(Elr)(\\\$|#)\ ]] || err_exit $'\'# \' not matching RE \\'\$|#\''
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$foo" == ~(Elr)('\$'|#)\ ]] || err_exit $'\'# \' not matching RE \'\\$\'|#\''
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ '\$' == '\$'* ]] || err_exit $'\'\\$\' not matching \'\\$\'*'