DASH Shell discussions
 help / color / mirror / Atom feed
* Parameter expansion fails when assigning a local variable
@ 2009-06-22  8:13 Jesper Bengtsson
  2009-06-22  8:57 ` Herbert Xu
  0 siblings, 1 reply; 10+ messages in thread
From: Jesper Bengtsson @ 2009-06-22  8:13 UTC (permalink / raw)
  To: 'dash@vger.kernel.org'

[-- Attachment #1: Type: text/plain, Size: 592 bytes --]

Hi,

I've found a problem with expanding $@.
If I declare a local variable and assigns the expanded positional parameters:
        local v="$@"
It fails with something like:
        local: 20: \/: bad variable name

If I split declaration and assignment into two lines it will work:
        local v
        v="$@"

I've tried this on dash 0.5.5.1 and 0.5.3 and both fail in the same way.
I've also tried on bash and ash (Busybox) and both handles declaration and assignment on one line.

I'm attaching a small script that shows the problem.

Best regards,
Jesper Bengtsson

[-- Attachment #2: dash-arg-bug.sh --]
[-- Type: application/octet-stream, Size: 371 bytes --]

#!/bin/dash

set -e
#set -x
#set -v

func() {
	local v="$@"	# unexpected behaviour == bug
	# v="$@"	# expected behaviour
	# local v	# also expected behaviour with declaration
	# v="$@"	# and asignment on separate lines

	echo "func: v='$v', \$1='$1', \$2='$2', \$3='$3'" >&2

	echo "$v"
}

xyz=" 	  123	 	xyz	\\/ 	"
echo "in:  '$xyz'"
abc=$(func $xyz)
echo "out: '$abc'"

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

end of thread, other threads:[~2009-07-03 21:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-22  8:13 Parameter expansion fails when assigning a local variable Jesper Bengtsson
2009-06-22  8:57 ` Herbert Xu
2009-06-28 21:39   ` Cristian Ionescu-Idbohrn
2009-06-29  0:47     ` Herbert Xu
2009-06-29 17:10       ` Cristian Ionescu-Idbohrn
2009-06-30  1:38         ` Herbert Xu
2009-06-30 16:17           ` Cristian Ionescu-Idbohrn
2009-07-01  7:42             ` Oleg Verych
2009-07-02 16:53               ` Cristian Ionescu-Idbohrn
2009-07-03 21:14                 ` Oleg Verych

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox