Simple shell script

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2008
Posts: 12
Reputation: iceman29 is an unknown quantity at this point 
Solved Threads: 2
iceman29's Avatar
iceman29 iceman29 is offline Offline
Newbie Poster

Simple shell script

 
0
  #1
May 11th, 2009
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.
Learn to appreciate and appreciate to learn.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Simple shell script

 
0
  #2
May 11th, 2009
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'.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 12
Reputation: iceman29 is an unknown quantity at this point 
Solved Threads: 2
iceman29's Avatar
iceman29 iceman29 is offline Offline
Newbie Poster

Re: Simple shell script

 
0
  #3
May 11th, 2009
Yeah.. that worked... Thanks...
Learn to appreciate and appreciate to learn.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC