943,915 Members | Top Members by Rank

Ad:
May 11th, 2009
0

Simple shell script

Expand Post »
Hi,

I am writing a shell script, and need help with a small piece of code.
It is as below:
Shell Scripting Syntax (Toggle Plain Text)
  1. CUST_1=filename
  2. b=1
  3. c=$CUST_$b
  4. echo $c

I want the output from this as filename, whereas I get it as 1.
Please guide as if where am I going wrong in here.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Newbie Poster
iceman29 is offline Offline
12 posts
since Feb 2008
May 11th, 2009
0

Re: Simple shell script

Weird, but it can be done.

Shell Scripting Syntax (Toggle Plain Text)
  1. CUST_1=filename
  2. b=1
  3. eval c=\$CUST_$b
  4. echo $c

There may be easier ways to do what you mean, like using an array. But this works, and gets points for being 'clever'.
Reputation Points: 51
Solved Threads: 35
Posting Whiz in Training
Fest3er is offline Offline
238 posts
since Aug 2007
May 11th, 2009
0

Re: Simple shell script

Yeah.. that worked... Thanks...
Reputation Points: 10
Solved Threads: 2
Newbie Poster
iceman29 is offline Offline
12 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Piping to "open command"
Next Thread in Shell Scripting Forum Timeline: ZIP Script modified - Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC