Date: Sat, 21 Mar 1998 13:40:02 -0800 (PST) From: Tor Egge <Tor.Egge@idi.ntnu.no> To: freebsd-bugs Subject: Re: bin/6087: sh doesn't work properly on certain configuration scripts Message-ID: <199803212140.NAA06380@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/6087; it has been noted by GNATS. From: Tor Egge <Tor.Egge@idi.ntnu.no> To: giffunip@asme.org Cc: freebsd-gnats-submit@FreeBSD.ORG Subject: Re: bin/6087: sh doesn't work properly on certain configuration scripts Date: Sat, 21 Mar 1998 22:33:54 +0100 ----Next_Part(Sat_Mar_21_22:32:09_1998)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit ash removes quoting information during parsing, thus the evaluation pass is not able to differentiate between ""$foobar and $foobar This breaks proper handling of word splitting. When $foobar expands to a single space, bash misbehaves too, for a slightly different reason. bash and ksh93 seems to perform word splitting differently: ( IFS="beh"; foobar="ghi"; echo "abc"abc$foobar "def"def ) bash gives abca cg i defdef ksh93 gives abcabcg i defdef bash seems to follow POSIX 1003.2 draft 11.2 while ksh93 seems to follow spec1170 for this example. I'm using some patches that changes the word splitting handling for ash in an attempt to follow spec 1170 while not being bug compatible with ksh93. Thus your test script does not complain when run on my development system. A slightly bigger test script is appended here. It reveals some of the other anomalies in bash and ksh93. - Tor Egge ----Next_Part(Sat_Mar_21_22:32:09_1998)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Description: "sh-ifs-test" #!/bin/sh echo "Tests of IFS handling and word splitting, v1.0 running" exec 2>&1 if [ `echo -n | wc -l` = 0 ] then echo1="-n" echo2="--> " echo3="" else echo1="" echo2="--> \c" echo3="\c" fi echo '[OIFS="$IFS"]' OIFS="$IFS" # echo '[var="*"]' # var="*" # echo $echo1 '[echo $var] ' "$echo2" # echo $var # echo $echo1 '[echo "$var"] ' "$echo2" # echo "$var" showargs() { XIFS="$IFS" IFS=" " for arg in "$@" do echo $echo1 "'$arg' $echo3" done echo IFS="$XIFS" } echo '[set abc "def ghi" jkl]' set abc "def ghi" jkl echo $echo1 '[showargs $*] ' "$echo2" showargs $* echo $echo1 '[showargs "$*"] ' "$echo2" showargs "$*" echo $echo1 '[showargs $@] ' "$echo2" showargs $@ echo $echo1 '[showargs "$@"] ' "$echo2" showargs "$@" echo $echo1 '[showargs "xx$@yy"] ' "$echo2" showargs "xx$@yy" echo $echo1 '[showargs "$@$@"] ' "$echo2" showargs "$@$@" echo 'set "" abc "def ghi" "" jkl ""' set "" abc "def ghi" "" jkl "" echo $echo1 '[showargs $*] ' "$echo2" showargs $* echo $echo1 '[showargs "$*"] ' "$echo2" showargs "$*" echo $echo1 '[showargs $@] ' "$echo2" showargs $@ echo $echo1 '[showargs "$@"] ' "$echo2" showargs "$@" echo $echo1 '[showargs "xx$@yy"] ' "$echo2" showargs "xx$@yy" echo $echo1 '[showargs "$@$@"] ' "$echo2" showargs "$@$@" echo '[IFS=""]' IFS="" echo 'set "" abc "def ghi" "" jkl ""' set "" abc "def ghi" "" jkl "" echo $echo1 '[showargs $*] ' "$echo2" showargs $* echo $echo1 '[showargs "$*"] ' "$echo2" showargs "$*" echo $echo1 '[showargs $@] ' "$echo2" showargs $@ echo $echo1 '[showargs "$@"] ' "$echo2" showargs "$@" echo $echo1 '[showargs "xx$@yy"] ' "$echo2" showargs "xx$@yy" echo $echo1 '[showargs "$@$@"] ' "$echo2" showargs "$@$@" echo '[unset IFS]' unset IFS echo 'set "" abc "def ghi" "" jkl ""' set "" abc "def ghi" "" jkl "" echo $echo1 '[showargs $*] ' "$echo2" showargs $* echo $echo1 '[showargs "$*"] ' "$echo2" showargs "$*" echo $echo1 '[showargs $@] ' "$echo2" showargs $@ echo $echo1 '[showargs "$@"] ' "$echo2" showargs "$@" echo $echo1 '[showargs "xx$@yy"] ' "$echo2" showargs "xx$@yy" echo $echo1 '[showargs "$@$@"] ' "$echo2" showargs "$@$@" echo '[IFS=":"]' IFS=":" echo 'set "" abc "def ghi" "" jkl ""' set "" abc "def ghi" "" jkl "" echo $echo1 '[showargs $*] ' "$echo2" showargs $* echo $echo1 '[showargs "$*"] ' "$echo2" showargs "$*" echo $echo1 '[showargs $@] ' "$echo2" showargs $@ echo $echo1 '[showargs "$@"] ' "$echo2" showargs "$@" echo $echo1 '[showargs "xx$@yy"] ' "$echo2" showargs "xx$@yy" echo $echo1 '[showargs "$@$@"] ' "$echo2" showargs "$@$@" echo '[IFS=":$OIFS"]' IFS=":$OIFS" echo 'set "" abc "def ghi" "" jkl ""' set "" abc "def ghi" "" jkl "" echo $echo1 '[showargs $*] ' "$echo2" showargs $* echo $echo1 '[showargs "$*"] ' "$echo2" showargs "$*" echo $echo1 '[showargs $@] ' "$echo2" showargs $@ echo $echo1 '[showargs "$@"] ' "$echo2" showargs "$@" echo $echo1 '[showargs "xx$@yy"] ' "$echo2" showargs "xx$@yy" echo $echo1 '[showargs "$@$@"] ' "$echo2" showargs "$@$@" echo '[IFS="$OIFS:"]' IFS="$OIFS:" echo 'set "" abc "def ghi" " : " jkl ""' set "" abc "def ghi" " : " jkl "" echo $echo1 '[showargs $*] ' "$echo2" showargs $* echo $echo1 '[showargs "$*"] ' "$echo2" showargs "$*" echo $echo1 '[showargs $@] ' "$echo2" showargs $@ echo $echo1 '[showargs "$@"] ' "$echo2" showargs "$@" echo $echo1 '[showargs "xx$@yy"] ' "$echo2" showargs "xx$@yy" echo $echo1 '[showargs "$@$@"] ' "$echo2" showargs "$@$@" echo $echo1 '[showargs "" ab "" cd ef] ' "$echo2" showargs "" ab "" cd ef echo '[A=""]' A="" echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo $echo1 '[showargs ${A}""] ' "$echo2" showargs ${A}"" echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[showargs ""${A}] ' "$echo2" showargs ""${A} echo $echo1 '[showargs X${A}] ' "$echo2" showargs X${A} echo '[A=" "]' A=" " echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo $echo1 '[showargs ${A}""] ' "$echo2" showargs ${A}"" echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[showargs ""${A}] ' "$echo2" showargs ""${A} echo $echo1 '[showargs X${A}] ' "$echo2" showargs X${A} echo '[A=" "]' A=" " echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo $echo1 '[showargs ${A}""] ' "$echo2" showargs ${A}"" echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[showargs ""${A}] ' "$echo2" showargs ""${A} echo $echo1 '[showargs X${A}] ' "$echo2" showargs X${A} echo '[A=":"]' A=":" echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo $echo1 '[showargs ${A}""] ' "$echo2" showargs ${A}"" echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[showargs ""${A}] ' "$echo2" showargs ""${A} echo $echo1 '[showargs X${A}] ' "$echo2" showargs X${A} echo '[A="X:"]' A="X:" echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo '[A="X :"]' A="X :" echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo '[A="X : "]' A="X : " echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo '[A="X: "]' A="X: " echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo '[A="::"]' A="::" echo $echo1 '[showargs ${A}] ' "$echo2" showargs ${A} echo $echo1 '[showargs ${A}""] ' "$echo2" showargs ${A}"" echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[showargs ""${A}] ' "$echo2" showargs ""${A} echo $echo1 '[showargs X${A}] ' "$echo2" showargs X${A} echo '[A="ab:c:"]' A="ab:c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="ab: c:"]' A="ab: c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="ab : c:"]' A="ab : c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="ab c:"]' A="ab c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="a b:c:"]' A="a b:c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="a:b:c:"]' A="a:b:c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="a :b:c:"]' A="a :b:c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="a : b:c:"]' A="a : b:c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="a: b:c:"]' A="a: b:c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="a: b c:"]' A="a: b c:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A="a b c d e"]' A="a b c d e" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo $echo1 '[showargs "$A"] ' "$echo2" showargs "$A" echo '[A=" a b c d e "]' A=" a b c d e " echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo '[A=":a b c d :: e:"]' A=":a b c d :: e:" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo $echo1 '[echo $A] ' "$echo2" echo $A echo '[A=":a b c d :: f::"]' A=":a b c d :: f::" echo $echo1 '[showargs $A] ' "$echo2" showargs $A echo $echo1 '[echo $A] ' "$echo2" echo $A echo '[A=":"]' A=":" echo $echo1 '[showargs X${A}Y${A}X] ' "$echo2" showargs X${A}Y${A}X echo $echo1 '[showargs X${A}${A}X] ' "$echo2" showargs X${A}${A}X echo $echo1 '[showargs X${A}] ' "$echo2" showargs X${A} echo $echo1 '[showargs X${A}${A}] ' "$echo2" showargs X${A}${A} echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[showargs ${A}${A}X] ' "$echo2" showargs ${A}${A}X echo '[A="::"]' A="::" echo $echo1 '[showargs X${A}Y${A}X] ' "$echo2" showargs X${A}Y${A}X echo $echo1 '[showargs X${A}${A}X] ' "$echo2" showargs X${A}${A}X echo $echo1 '[showargs X${A}] ' "$echo2" showargs X${A} echo $echo1 '[showargs X${A}${A}] ' "$echo2" showargs X${A}${A} echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[showargs ${A}${A}X] ' "$echo2" showargs ${A}${A}X echo '[A=" ::"]' A=" ::" echo $echo1 '[showargs X${A}Y${A}X] ' "$echo2" showargs X${A}Y${A}X echo $echo1 '[showargs X${A}${A}X] ' "$echo2" showargs X${A}${A}X echo $echo1 '[showargs X${A}] ' "$echo2" showargs X${A} echo $echo1 '[showargs X${A}${A}] ' "$echo2" showargs X${A}${A} echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[showargs ${A}${A}X] ' "$echo2" showargs ${A}${A}X echo '[A="ab "]' A="ab " echo 'B=" cde"]' B=" cde" echo $echo1 '[showargs $A$B] ' "$echo2" showargs $A$B echo '[A="ab :"]' A="ab :" echo '[B=" cde"]' B=" cde" echo $echo1 '[showargs $A$B] ' "$echo2" showargs $A$B echo $echo1 '[showargs ${A}X] ' "$echo2" showargs ${A}X echo $echo1 '[echo "a:b:c"] ' "$echo2" echo "a:b:c" echo $echo1 '[echo "a:b\:c"] ' "$echo2" echo "a:b\:c" echo $echo1 '[echo a:b:c] ' "$echo2" echo a:b:c echo $echo1 '[echo a:b\:c] ' "$echo2" echo a:b\:c echo $echo1 '[echo a:b:c":d:e:f"] ' "$echo2" echo a:b:c":d:e:f" echo $echo1 '[echo a:b\:c":d:e\:f"] ' "$echo2" echo a:b\:c":d:e\:f" echo '[var="val:val2\:val3"]' var="val:val2\:val3" echo '[xvar=":val:val2\:val3"]' xvar=":val:val2\:val3" echo $echo1 '[echo $novar:b:c] ' "$echo2" echo $novar:b:c echo $echo1 '[echo $xvar] ' "$echo2" echo $xvar echo $echo1 '[echo "$var:b:c"] ' "$echo2" echo "$var:b:c" echo $echo1 '[echo "$var:b\:c"] ' "$echo2" echo "$var:b\:c" echo $echo1 '[echo $var:b:c] ' "$echo2" echo $var:b:c echo $echo1 '[echo $var:b\:c] ' "$echo2" echo $var:b\:c echo $echo1 '[echo $var:b:c":$var:e:f"] ' "$echo2" echo $var:b:c":$var:e:f" echo $echo1 '[echo $var:b\:c":$var:e\:f"]' "$echo2" echo $var:b\:c":$var:e\:f" echo $echo1 '[echo $var:`echo '\''h:i'\''`] ' "$echo2" echo $var:`echo 'h:i'` echo $echo1 '[echo $var:"`echo '\''h:i'\''`"] ' "$echo2" echo $var:"`echo 'h:i'`" echo '[IFS="${OIFS}a"]' IFS="${OIFS}a" echo '[HOME="harmless"]' HOME="/harmless" echo $echo1 '[echo ~] ' "$echo2" echo ~ echo $echo1 '[echo ~/$var] ' "$echo2" echo ~/$var echo $echo1 '[echo ~root] ' "$echo2" echo ~root echo $echo1 '[echo ~roo'\''t'\''] ' "$echo2" echo ~roo't' echo $echo1 '[echo ~roo"t"] ' "$echo2" echo ~roo"t" echo $echo1 '[echo ~root\/] ' "$echo2" echo ~root\/ echo $echo1 '[echo \~root] ' "$echo2" echo \~root echo $echo1 '[echo "~"root] ' "$echo2" echo "~"root echo $echo1 '[echo var:bad:bad] ' "$echo2" echo var:bad:bad echo $echo1 '[echo $var:bad:bad] ' "$echo2" echo $var:bad:bad echo $echo1 '[echo $var:bad:"bad"] ' "$echo2" echo $var:bad:"bad" echo $echo1 '[echo $var:bad:'\''bad'\''] ' "$echo2" echo $var:bad:'bad' if [ ! `echo "$((4+4))"` = 8 ] then echo "Extended syntax not supported." exit 0 fi echo '[IFS="${OIFS}:"]' IFS="${OIFS}:" echo $echo1 '[echo $var:$(echo '\''f:g'\'')] ' "$echo2" echo $var:$(echo 'f:g') echo $echo1 '[echo $var:"$(echo '\''f:g'\'')"] ' "$echo2" echo $var:"$(echo 'f:g')" echo $echo1 '[echo $var:$((4+4))] ' "$echo2" echo $var:$((4+4)) echo '[IFS="${OIFS}6"]' IFS="${OIFS}6" echo $echo1 '[echo 262144:$((13*13))] ' "$echo2" echo 262144:$((13*13)) echo $echo1 '[echo 262144":$((13*13))"] ' "$echo2" echo 262144":$((13*13))" # No shells seems to support this construct, due to separate passes # for parsing and evaluation: # echo "$((4+`echo '4))'`" # If parsing was performed during evaluation, the result could be # "$((4+`echo '4))'`" (initial state) # "$((4+`echo '4))'`" (after tilde expansion) # "$((4+`echo '4))'`" (after parameter expansion) # "$((4+4))" (after command substitution) # "8" (after arithmetic expansion) # "8" (after field splitting) # "8" (after pathname expansion) # 8 (after quote removal) ----Next_Part(Sat_Mar_21_22:32:09_1998)---- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803212140.NAA06380>