|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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... |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
Can you paste the code snippet around this?... exact code snippet...
--ahamed |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Resolve Environment Variable
Here is my code... 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" Last edited by Franklin52; 02-09-2012 at 03:06 AM.. Reason: Please use code tags for code and data samples, thank you |
|
#4
|
||||
|
||||
|
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 |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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... Code:
+ 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: Last edited by Franklin52; 02-09-2012 at 03:07 AM.. Reason: code tags |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Try this change in your script... Code:
actual_dir=$( eval echo $in_loc ) cd $actual_dir --ahamed |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
That works... Thank you very much...
|
| Sponsored Links | ||
|
|
![]() |
| Tags |
| environment variables, ksh |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Expand an environment variable in sed, when the variable contains a slash | Ilja | Shell Programming and Scripting | 2 | 11-10-2010 09:58 AM |
| Add Environment variable in C/C++ | Kattoor | Programming | 2 | 04-30-2009 06:00 AM |
| set environment variable? | smartgupta | Solaris | 8 | 09-15-2008 01:01 PM |
| Resolve a Variable | serm | Shell Programming and Scripting | 2 | 05-12-2005 12:27 AM |
| Environment Variable | thumsup9 | UNIX for Dummies Questions & Answers | 2 | 02-03-2005 06:45 PM |
|
|