Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[BUG] var=$* and var=$@ create array with SHWORDSPLIT and null or unset IFS
- X-seq: zsh-workers 40564
- From: Martijn Dekker <martijn@xxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [BUG] var=$* and var=$@ create array with SHWORDSPLIT and null or unset IFS
- Date: Fri, 17 Feb 2017 00:05:13 +0100
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
In SHWORDSPLIT mode, if IFS is null (no field splitting) or unset
(default fieldsplitting), both var=$* and var=$@ act like var=("$@"), so
turn 'var' into an array.
In native mode, zsh acts correctly (POSIXly), i.e.: all the parameters
get concatenated with no separator, since IFS is null. So this should be
fixed for sh mode.
Note that var="$@" and var="$*" act correctly in any mode. So, to
trigger the bug:
- the quotes must be absent
- IFS must be null (i.e. set and empty) or unset
- SHWORDSPLIT must be on
Here's a little test script.
#! Src/zsh -f
set -- *
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
(set -x; eval "$testcmd")
done
done
done
You see the bug happen under "--- null IFS, sh splitting ---" and "---
unset IFS, sh splitting ---":
--- null IFS, sh splitting ---
+test.zsh:19> eval 'var=$@'
+(eval):1> var=( Config Doc Etc Makefile Src Test config.cache config.h
config.log config.modules config.modules.sh config.status stamp-h
test.zsh )
+test.zsh:19> eval 'var=$*'
+(eval):1> var=( Config Doc Etc Makefile Src Test config.cache config.h
config.log config.modules config.modules.sh config.status stamp-h
test.zsh )
[...]
--- unset IFS, sh splitting ---
+test.zsh:19> eval 'var=$@'
+(eval):1> var=( Config Doc Etc Makefile Src Test config.cache config.h
config.log config.modules config.modules.sh config.status stamp-h
test.zsh )
+test.zsh:19> eval 'var=$*'
+(eval):1> var=( Config Doc Etc Makefile Src Test config.cache config.h
config.log config.modules config.modules.sh config.status stamp-h
test.zsh )
Thanks,
- M.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author