[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: OT: sed help
On Tue, Jun 04, 2002 at 03:17:18PM -0700, James A. Peltier wrote:
> sorry for this OT question regarding sed.
>
> I'm trying to take command line user input and pipe it to sed
> for parsing. currently i have this
>
> [joshua:] vi test
> #!/bin/sh
> VALUE1=$1
> VALUE2=$2
>
> echo $VALUE1 $VALUE2 > text.tmp
> sed 's/$VALUE1/$VALUE2/' text.tmp > textfile
>
> for some reason this doesn't work when I try
>
> [joshua:] sh test test1 test2
>
> any ideas why? I'm certainly no sed expert as many can see.
> What would be the easiest way to implement this?
You're using the worng quotes. Variable interpolation only happens
with double quotes, not single. Compare:
$ FOO=bar
$ echo $FOO
bar
$ echo "FOO is $FOO"
FOO is bar
$ echo 'FOO is $FOO'
FOO is $FOO
$
And, yes, there are much better places to ask these questions. You
might start with:
http://www.trumpetpower.com/OpenBSD/Meta-FAQ#basic_unix
You should also read sh (1)--this is pretty basic stuff, all
covered in the man page and any other (Bourn-style) shell
programming reference.
b&
--
Ben Goren
mailto:ben@trumpetpower.com
http://www.trumpetpower.com/
icbm:33o25'37"N_111o57'32"W
[demime 0.98d removed an attachment of type application/pgp-signature]