Shell scripting question [newby]

Jan Grant jan.grant at
Mon Apr 10 08:56:17 UTC 2006

On Mon, 10 Apr 2006, Malcolm Fitzgerald wrote:

> On 10/04/2006, at 12:39 AM, Jan Grant wrote:
> > On Sun, 9 Apr 2006, Malcolm Fitzgerald wrote:
> > 
> > > I'm trying to follow the instructions at
> > > <>

> Your advice got me to step 7 where the need to pass a control structure to the
> loop stopped me again.
> I got a bash shell and I write:
> for dist in base dict doc games info manpages ports; do
>         cat /mnt/6.0-RELEASE/${dist}/${dist}.?? > /usr/${dist}.tgz
> done
> I put it onto three lines by typing "\" at the end of each line to achieve the
> layout and I get the prompt ">". When I get to the end, ie, "done" I press
> Enter and get another prompt.
> How can I get the multi-line command executed?

What you're doing is roughly this: (note, I supplied a separate "done", 
you'll see why)

$ for i in one two three; do \
> echo $i \
> done
> done
one done
two done
three done

the first "done" is counted as part of the "echo" argument list.

If you terminate a line with a "\" character, then the intervening 
newline is treated as "just whitespace". Consequently, were you to use 
this syntax, you'd need to punctuate your script properly:

	for i in one two three; do \
		echo $i; \

Having said that, you don't need the "\" marks, because bash (and sh) 
are smart enough to parse as you go and keep prompting until the command 
is complete. Thus you can just type:

	for i in one two three; do
		echo $i

and it'll do what you're asking.


jan grant, ISYS, University of Bristol.
Tel +44 (0)117 3317661
Strive to live every day as though it was last Wednesday.

More information about the freebsd-questions mailing list