zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] var=$* and var=$@ create array with SHWORDSPLIT and null or unset IFS
@ 2017-02-16 23:05 Martijn Dekker
  2017-02-17  0:07 ` Martijn Dekker
  2017-02-17  5:14 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: Martijn Dekker @ 2017-02-16 23:05 UTC (permalink / raw)
  To: Zsh hackers list

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-20 22:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-16 23:05 [BUG] var=$* and var=$@ create array with SHWORDSPLIT and null or unset IFS Martijn Dekker
2017-02-17  0:07 ` Martijn Dekker
2017-02-17  5:14 ` Bart Schaefer
2017-02-20 18:58   ` Bart Schaefer
2017-02-20 21:20     ` Bart Schaefer
2017-02-20 22:13       ` Martijn Dekker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).