Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parameter parsing from file

Status
Not open for further replies.

hokky

Technical User
Nov 9, 2006
170
AU
Hi guys,

I've got simple question, but I couldn't work it out atm.

I try to parse the value from source file here's the contain of source file
Code:
$ALGO_TOP/static/scripts/viewTradeLSno.ksh

And here's my script:
Code:
#file=`cat source`
#file=$ALGO_TOP/static/scripts/viewTradeLSno.ksh
echo $file

if [[ -f $file ]]
then
        echo "file is found"
else
        echo "file is not found"
fi

if I use the first "file" parameter is not working but
if I use the second "file" parameter is working

both actually has the same value

Any idea what should I do if I want the use the first parameter ?
 
cat-ing a file will not expand any variables you think are referenced in that file...

Code:
file=`cat source`

# in your case this is the same as
file='$ALGO_TOP/static/scripts/viewTradeLSno.ksh'

echo $file

if [[ -f $file ]]
then
        echo "file is found"
else
        echo "file is not found"
fi

you can get where you want to go with the eval subcommand

Code:
line=`cat $source`
eval file=$line

echo $file

if ...


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top