Date: Thu, 27 Mar 1997 18:24:28 +1030 (CST) From: grog@lemis.de To: email@john.net (John Clark) Cc: questions@freebsd.org Subject: Re: BASH -> passing cmd line params Message-ID: <199703270754.SAA00211@papillon.lemis.de> In-Reply-To: <3.0.1.32.19970325173551.00aa5260@199.3.74.250> from John Clark at "Mar 25, 97 05:35:51 pm"
next in thread | previous in thread | raw e-mail | index | archive | help
John Clark writes: > Hello, I am having trouble passing a variable with a space in it as a > single parameter. Is there a way to do this? > > > #!/bin/sh > > PARAM1="hello world" > PARAM2="foo" > PARAM3="bar" > > mycommand $PARAM1 $PARAM2 $PARAM3 > > > The output of the above script shows 4 command line variables: 1=hello, > 2=world, 3=foo, 4=bar > > I would like: 1=hello world, 2=foo, 3=bar > > Any help would be Sure. This is a feature, not a bug. It isn't specific to bash; other Bourne shell derivatives will do the same thing. Think of how the shell resolves mycommand $PARAM1 $PARAM2 $PARAM3 It just replaces the $PARAMs with their contents, so you get mycommand hello world foo bar Now consider what happens when you do: mycommand "$PARAM1" "$PARAM2" "$PARAM3" This time you get mycommand "hello world" "foo" "bar" Greg
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199703270754.SAA00211>