Re: [Probably] silly question
From: David Thompson (foobar@foobar.com)
Date: 04/16/03
- Next message: Juergen Heck: "Re: ShellScript"
- Previous message: David Thompson: "Re: count words"
- In reply to: Tricky Dicky: "Re: [Probably] silly question"
- Next in thread: David Thompson: "Re: [Probably] silly question"
- Reply: David Thompson: "Re: [Probably] silly question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "David Thompson" <foobar@foobar.com> Date: Wed, 16 Apr 2003 16:37:31 GMT
"Tricky Dicky" <trickydicky99@hotmail.com> wrote
> On Wed, 16 Apr 2003 11:35:37 +0200, "Laurent Le Boterve"
> >"Tricky Dicky" <trickydicky99@hotmail.com>
> >> I'm using the bourne shell for College. If I have the following 3
> >> variables:
> >>
> >> $one="vari" $two="able" $variable="Working"
> >>
> >> How would I get the shell to echo "Working" by using the values of the
> >> two other variables? Is it possible?
> >
> >$ one="vari" ;two="able" ;variable="Working"
> >$ eval echo '$'$one$two
> >Working
>
> Thank you so much. I had been scratching my head for a while trying to
> do that one :)
Think in terms of the steps needed. First build the name of
the variable, and echo that,
echo "$one$two"
but you know you need a $ in front, and you know you have to
escape the $ to protect it from echo, so now do that,
echo "\$$one$two"
now you're golden, put the eval in front and now echo will
print the value of $variable, rather than string "$variable",
eval echo "\$$one$two"
Easy, huh?
-- David Thompson
- Next message: Juergen Heck: "Re: ShellScript"
- Previous message: David Thompson: "Re: count words"
- In reply to: Tricky Dicky: "Re: [Probably] silly question"
- Next in thread: David Thompson: "Re: [Probably] silly question"
- Reply: David Thompson: "Re: [Probably] silly question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]