Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 May 2002 14:26:14 -0500
From:      Dan Nelson <dnelson@allantgroup.com>
To:        Archie Cobbs <archie@dellroad.org>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: sh 'here document' question
Message-ID:  <20020520192614.GA88336@dan.emsphone.com>
In-Reply-To: <200205201905.g4KJ5MM53848@arch20m.dellroad.org>
References:  <200205201905.g4KJ5MM53848@arch20m.dellroad.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (May 20), Archie Cobbs said:
> Is this supposed to work? It doesn't.
> 
>     $ cat foo.sh 
>     PREFIX=foo
>     SUFFIX=bar
>     . << xxxEOFxxx
>     ${PREFIX}${SUFFIX}=abc
>     xxxEOFxxx
>     echo foobar=${foobar}
>     $ sh foo.sh 
>     foobar=
>     $

I don't think it's supposed to work.  A here-document basically says
"instead of treating the word after << as a filename to open, just read
the current script source until you hit the word, and pass that to the
program's stdin".  So what you end up is the command "." with
"${PREFIX}${SUFFIX}=abc\n" waiting on stdin.  Since "." with no args is
basically a no-op, nothing happened.

You are probably looking for the "eval" command, which will do variable
expeansion on a line, then execute it.

-- 
	Dan Nelson
	dnelson@allantgroup.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020520192614.GA88336>