From owner-freebsd-questions Sat Mar 29 16:17:09 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id QAA23164 for questions-outgoing; Sat, 29 Mar 1997 16:17:09 -0800 (PST) Received: from papillon.lemis.de (papillon.blaze.net.au [203.17.53.74]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id QAA23143; Sat, 29 Mar 1997 16:16:51 -0800 (PST) Received: (grog@localhost) by papillon.lemis.de (8.8.4/8.6.12) id SAA00211; Thu, 27 Mar 1997 18:24:29 +1030 (CST) From: grog@lemis.de Message-Id: <199703270754.SAA00211@papillon.lemis.de> Subject: Re: BASH -> passing cmd line params In-Reply-To: <3.0.1.32.19970325173551.00aa5260@199.3.74.250> from John Clark at "Mar 25, 97 05:35:51 pm" To: email@john.net (John Clark) Date: Thu, 27 Mar 1997 18:24:28 +1030 (CST) Cc: questions@freebsd.org Organisation: LEMIS, Schellnhausen 2, 36325 Feldatal, Germany Phone: +49-6637-919123 Fax: +49-6637-919122 Reply-to: grog@lemis.de (Greg Lehey) WWW-Home-Page: http://www.FreeBSD.org/~grog X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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