[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Unable to do a for loop in "here document"
From: |
Stephane Chazelas |
Subject: |
Re: Unable to do a for loop in "here document" |
Date: |
Wed, 9 Jul 2008 08:26:42 +0100 |
User-agent: |
Mutt/1.5.16 (2007-09-19) |
On Tue, Jul 08, 2008 at 08:44:47PM -0700, Mr Aras wrote:
[...]
> #!/bin/sh
> sh <<-EOF
> for word in hello world
> do
> echo word = $word
> done
> EOF
>
> output is:
> word =
> word =
>
>
> Can someone tell me why this doesn't work? I've been going nuts trying to
> figure this one out.
[...]
Variables are expanded in here documents unless you quote
something in the terminator. So the above becomes:
sh <<-EOF
for word in hello world
do
echo word =
done
EOF
You want:
sh <<-\EOF
for word in hello world
do
echo word = $word
done
EOF
(or E"O"F or 'EOF' ...)
--
Stéphane