For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > August 2004 > Re: Substituting the value of an environment variable that is passed









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 Re: Substituting the value of an environment variable that is passed
Billy N. Patton

2004-08-23, 4:00 pm

Anil Venugopalan wrote:
> 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.


csh
set path = $1;

bash
path=$1;


--
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455, b-patton@ti.com
Nick Landsberg

2004-08-23, 4:00 pm

Billy N. Patton wrote:
> Anil Venugopalan wrote:
>
>
>
> csh
> set path = $1;
>
> bash
> path=$1;
>
>


That's not what the OP requested.

Check out

man 1 dirname

for what you want.

NPL


--
"It is impossible to make anything foolproof
because fools are so ingenious"
- A. Bloch
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com