simple sh question

simple sh question

Post by bean » Thu, 21 Nov 2002 18:33:55



hi ,

i'm trying to write a shell script that uses dynamic variables created by
the user and can't figure out how to do this :
i'd like to concatenate a string to a variable and get the result of the
concatenation as a variable like this test script shows.

#!/bin/sh

# my variable
string="my word"

# my second variable
b="ring"

echo $string             # this works : gives me : my word

# concatenate a string to $b to get the word "string" and try to evaluate it
to make it $string and get the result
echo $("st"$b)          # this doesn't, but i need to acheive this

Can someone kindly give me a hint :)

Thanks

Tom

 
 
 

simple sh question

Post by Bill Marcu » Thu, 21 Nov 2002 18:59:21


On Wed, 20 Nov 2002 10:33:55 +0100,

Quote:> hi ,

> i'm trying to write a shell script that uses dynamic variables created by
> the user and can't figure out how to do this :
> i'd like to concatenate a string to a variable and get the result of the
> concatenation as a variable like this test script shows.

> Can someone kindly give me a hint :)

The old eval question again...

 
 
 

simple sh question

Post by bean » Thu, 21 Nov 2002 19:14:05


thx :) it was eval
wasn't sure which path to take



> On Wed, 20 Nov 2002 10:33:55 +0100,

> > hi ,

> > i'm trying to write a shell script that uses dynamic variables created
by
> > the user and can't figure out how to do this :
> > i'd like to concatenate a string to a variable and get the result of the
> > concatenation as a variable like this test script shows.

> > Can someone kindly give me a hint :)

> The old eval question again...

 
 
 

simple sh question

Post by Damian Ibbotso » Thu, 21 Nov 2002 19:54:04


$bar=foo
$foo=bar
$eval echo \$$foo
foo

--
Posted via http://dbforums.com

 
 
 

simple sh question

Post by David Walli » Fri, 22 Nov 2002 01:41:45



> On Wed, 20 Nov 2002 10:33:55 +0100,

> > hi ,

> > i'm trying to write a shell script that uses dynamic variables created by
> > the user and can't figure out how to do this :
> > i'd like to concatenate a string to a variable and get the result of the
> > concatenation as a variable like this test script shows.

> > Can someone kindly give me a hint :)

> The old eval question again...

Didn't Seinfeld do an episode on eval?

--
David Wallis

 
 
 

simple sh question

Post by mats.blomstr.. » Sat, 23 Nov 2002 01:14:21


        bash$ b="ring"
        bash$ echo st$b
        string
        bash$

//Mats

--
My code (if any) in this message are Copyright (C) 2002 Mats Blomstrand
and licensed under GNU GPL, http://www.gnu.org/licenses/gpl.html

 
 
 

1. simple sh question.

I'm trying to write a simple script to convert *.gif to *.jpg.  Here's the
code:

#!/bin/sh

for file in *.gif
  do
     temp = `cut -d. -f1 $file`
     cjpeg <$temp>$temp.jpg
     echo compressing $temp.gif to $temp.jpg
  done

unfortunately, it seems that instead of trying to cut the filename, it's
trying to cut the file itself!  Also, naming convention doesn't seem to
work. Is there a way to rename *.gif to *.jpg as in DOS rename command?

TIA

James

2. Serial Ports

3. Simple sh script, simple error?

4. Help: /tmp/ccwQcenk.o(.text+0x14): undefined reference to `pcap_lookupdev'

5. simple question re: sh

6. REAL3D Startfighter Video Card Not Found in I740 driver

7. a simple /bin/sh script question

8. 3Com EtherLink III and Solaris 7 x86 - Please Help

9. Execute a sh script under perl and sh: sh script; perl script?

10. A simple question deserving a simple answer

11. a simple sed question ( there all simple :> )

12. Simple question from simple user

13. Simple FTP question (very simple)