Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] var=$* and var=$@ create array with SHWORDSPLIT and null or unset IFS
Op 17-02-17 om 00:05 schreef Martijn Dekker:
> Here's a little test script.
Figured I might as well save you some work and turn it into a proper zsh
test case instead.
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 9128c3c..ca1dcc2 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -2056,3 +2056,81 @@
0:Regression: "-" became Dash in workers/37689, breaking ~- expansion
*>*
F:We do not care what $OLDPWD is, as long as it doesn't cause an error
+
+ (
+ set -- one 'two three' four
+ for ifs in default null unset; do
+ for wordsplit in native sh; do
+ print -r -- "--- $ifs IFS, $wordsplit splitting ---"
+ case $ifs in
+ default) IFS=$' \t\n\00' ;;
+ null) IFS= ;;
+ unset) unset -v IFS ;;
+ esac
+ case $wordsplit in
+ native) unsetopt shwordsplit ;;
+ sh) setopt shwordsplit ;;
+ esac
+ for testcmd in 'var=$@' 'var=$*' 'var="$@"' 'var="$*"'; do
+ print -r -- "> $testcmd"
+ eval "$testcmd"
+ printf '[%s]\n' "${var[@]}"
+ done
+ done
+ done
+ )
+0:Assigning $@, $*, "$@", "$*" to var with various shwordsplit/IFS settings
+>--- default IFS, native splitting ---
+>> var=$@
+>[one two three four]
+>> var=$*
+>[one two three four]
+>> var="$@"
+>[one two three four]
+>> var="$*"
+>[one two three four]
+>--- default IFS, sh splitting ---
+>> var=$@
+>[one two three four]
+>> var=$*
+>[one two three four]
+>> var="$@"
+>[one two three four]
+>> var="$*"
+>[one two three four]
+>--- null IFS, native splitting ---
+>> var=$@
+>[one two three four]
+>> var=$*
+>[onetwo threefour]
+>> var="$@"
+>[one two three four]
+>> var="$*"
+>[onetwo threefour]
+>--- null IFS, sh splitting ---
+>> var=$@
+>[one two three four]
+>> var=$*
+>[onetwo threefour]
+>> var="$@"
+>[one two three four]
+>> var="$*"
+>[onetwo threefour]
+>--- unset IFS, native splitting ---
+>> var=$@
+>[one two three four]
+>> var=$*
+>[one two three four]
+>> var="$@"
+>[one two three four]
+>> var="$*"
+>[one two three four]
+>--- unset IFS, sh splitting ---
+>> var=$@
+>[one two three four]
+>> var=$*
+>[one two three four]
+>> var="$@"
+>[one two three four]
+>> var="$*"
+>[one two three four]
Messages sorted by:
Reverse Date,
Date,
Thread,
Author