Unix Programming - Substituting the value of an environment variable that is passed as a shell script par

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > August 2004 > Substituting the value of an environment variable that is passed as a shell script par





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

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

2004-08-23, 5: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.
SM Ryan

2004-08-23, 5: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?
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com