`set' in der shell: Bug?

Jan-Benedict Glaw jbglaw at lug-owl.de
Mon May 31 17:34:12 CEST 2010


Hallo!

Ich wollte mal fix die Parameter eines C'ischen Funktionsaufrufes
in der shell parsen (und schmeiß' dafür die äußeren Klammern weg.)
Wenn im Ergebnis ersteinmal noch die  ',' (am Ende eines jeden
Arguments drin sind, wär' das kein Problem:

Input:
	asdf, "Foo this is", NULL, 17.3

Output soll sein, daß

	$1 = adsf,
	$2 = Foo this is,
	$3 = NULL,
	$4 = 17.3

ist. Klappt auch, solange man

	set asdf, "Foo this is", NULL, 17.3

macht, scheint aber fehlzuschlagen, wenn der Text aus einer Variablen
kommt:

#!/usr/bin/env sh
echo ${BASH_VERSION}
set foo "bar baz" stuff
echo "1: $1    2: $2   3: $3"
X='foo "bar baz" stuff'
set $X
echo "1: $1    2: $2   3: $3"
set `echo $X`
echo "1: $1    2: $2   3: $3"


Das ergibt dann:

3.1.17(1)-release
1: foo    2: bar baz   3: stuff
1: foo    2: "bar   3: baz"
1: foo    2: "bar   3: baz"


Erwartet hätte ich in allen drei Fällen das Ergebnis der ersten Zeile.
Die Ergebnisse der zweiten und dritten Zeile halte ich für falsch.

Comments?  Workarounds?

MfG, JBG

-- 
      Jan-Benedict Glaw      jbglaw at lug-owl.de              +49-172-7608481
Signature of:              What we do for ourselves dies with us. What we do for
the second  :         others and the world remains and is immortal. (Albert Pine)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lug-owl.de/pipermail/linux/attachments/20100531/4fe5ab3d/attachment.sig>


More information about the Linux mailing list