zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [BUG] var=$* and var=$@ create array with SHWORDSPLIT and null or unset IFS
Date: Fri, 17 Feb 2017 00:05:13 +0100	[thread overview]
Message-ID: <62e5833f-14b1-b42b-31af-2f1532b565ed@inlv.org> (raw)

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.


             reply	other threads:[~2017-02-16 23:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-16 23:05 Martijn Dekker [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=62e5833f-14b1-b42b-31af-2f1532b565ed@inlv.org \
    --to=martijn@inlv.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).