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



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