Substituting the value of an environment variable that is passed as a shell script par
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Substituting the value of an environment variable that is passed as a shell script par




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Substituting the value of an environment variable that is passed as a shell script par  
Anil Venugopalan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-23-04 10:55 PM

I have a shell script that accepts a filename as parameter. The
filename may or may not include an environment variable. For
instance,the filename could be either:
a) /abc/def/file.dat, or
b) $FILE_PATH/file.dat, where $FILE_PATH=/abc/def

In the latter case, I want to be able to substitute '/abc/def'
wherever $FILE_PATH is referenced.

I know one way of doing it is to use 'cut' statement to get to
'FILE_PATH', then do an 'env|grep FILE_PATH' to derive this value, but
is there an easier way out?

If I do an 'echo $1' (assuming the filename parameter is $1), it shows
"$FILE_PATH/file.dat". What I want to be able to see is
"/abc/def/file.dat" without making it too cumbersome.

Appreciate any feedback.

Thanks
Anil.





[ Post a follow-up to this message ]



    Re: Substituting the value of an environment variable that is passed as a shell script  
SM Ryan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-23-04 10:55 PM

# If I do an 'echo $1' (assuming the filename parameter is $1), it shows
# "$FILE_PATH/file.dat". What I want to be able to see is
# "/abc/def/file.dat" without making it too cumbersome.

I don't know if there's a more elegant solution but

@ p=x/y/z
@ q='$p/y/z'
@ echo $p
x/y/z
@ eval echo $p
x/y/z
@ echo $q
$p/y/z
@ eval echo $q
x/y/z/y/z


--
SM Ryan http://www.rawbw.com/~wyrmwif/
If your job was as meaningless as theirs, wouldn't you go crazy too?





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:28 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register