Resolve Environment Variable

I am tyring to resolve an environment variable that is part of a string I selected from our database.
Simply put, I want cd to this folder before checking if a file exists.

The variable $in_loc has the value '$PS_HOME/int/VSP' where $PS_HOME is the environment variable.

I am using cd $in_loc in my ksh script, however it doesn't work. I get the error './getfile.sh[29]: $PS_HOME/int/VSP: not found'.

can anyone help me out. I have tried several things including readlink, realpath, and various forms of the cd command, but can't seem to get it to work...

Can you paste the code snippet around this?... exact code snippet...

--ahamed

Here is my code...

#!/bin/ksh
echo "------------------------------"
echo "Scripting ls command..."
echo "------------------------------"
 
SQLPLUS_CMD=$ORACLE_HOME/bin/sqlplus
login="userid/pwd@dev"
 
in_loc=`$SQLPLUS_CMD -s $login <<EOF 
set pagesize 0 feedback off verify off heading off echo off
select file_location from ps_is_ftp_rc where prcsname = 'HR1062' and seqnum = 1;
exit;
EOF`
 
filepath="cd "$in_loc
 
echo "filepath = $filepath"
echo "in_loc value: $in_loc"
 
cd $in_loc
 
echo `pwd`
 
my_file="testfile"
 
fname=`ls -t $my_file | head -1`
 
echo " "
echo "last edited filename: $fname"

So the data retrieved from the DB is "$PS_HOME/int/VSP"? Is $PS_HOME defined anywhere?

Please paste the output of bash -x /your/script

--ahamed

The results are listed below, however I removed sensitive info. $PS_HOME is defined and I can run the command 'cd $PS_HOME/int/VSP' at the command line and get the diesired results. It just doesn't work in my script...

+ echo ------------------------------
------------------------------
+ echo 'Scripting ls command...'
Scripting ls command...
+ echo ------------------------------
------------------------------
+ SQLPLUS_CMD=<oracle_home>/bin/sqlplus
+ login=<userid>/<pwd>@<db>
++ <oracle_home>/bin/sqlplus -s <userid>/<pwd>@db
+ in_loc='$PS_HOME/int/VSP'
+ filepath='cd $PS_HOME/int/VSP'
+ echo 'filepath = cd $PS_HOME/int/VSP'
filepath = cd $PS_HOME/int/VSP
+ echo 'in_loc value: $PS_HOME/int/VSP'
in_loc value: $PS_HOME/int/VSP
+ cd '$PS_HOME/int/VSP'
getfile.sh: line 25: cd: $PS_HOME/int/VSP: No such file or directory
++ pwd
+ echo <pwd> 
++ cd '$PS_HOME/int/VSP'
getfile.sh: line 29: cd: $PS_HOME/int/VSP: No such file or directory
+ echo
++ pwd
+ echo <pwd>

+ my_file=testfile
++ ls -t testfile
++ head -1
testfile: No such file or directory
+ fname=
+ echo ' '
+ echo 'last edited filename: '
last edited filename:
+ echo ' '
+ echo 'Found string at position:  '
Found string at position:

Try this change in your script...

actual_dir=$( eval echo $in_loc )
cd $actual_dir

--ahamed

That works... Thank you very much...