Register
It is currently Wed Oct 22, 2014 8:22 pm

Variable expanding changed....


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Dec 08, 2010 2:35 pm   

Joined: Wed Dec 08, 2010 2:26 pm
Posts: 1
We have scripts that grab variables from a parameter file that is not expanding the variables the same as they did in our old version of BASH/3.0. Below is a sample script to illustrate the issue we are having.

The script greps parameters from the parameter file. If one of the parameters is a set variable, WORK_DIR in example, it gets expanded during the execution of the command. When we run the same code on BASH/4.1, it doesn't expand the WORK_DIR variable.

[db_admin@orawarehs test]$ cat /u02/dbmaint/test/test.sh ### Test scripts
pfile=parameters.txt
WORK_DIR=/u02/dbmaint/test/

declare -a a_para=( $( grep '^' $pfile ) )
s_size=${#a_para[*]}

for (( s_ptr=0; s_ptr < s_size; s_ptr=s_ptr+1 ))
do
v_cmd=$v_cmd' '${a_para[($s_ptr)]}
done

echo 'Command:'$v_cmd
$v_cmd

exit
[db_admin@orawarehs test]$ cat /u02/dbmaint/test/parameters.txt ### Parameter File
/bin/ls -l $WORK_DIR/test.sh


[db_admin@orawarehs test]$ /u02/dbmaint/test/test.sh ### BASH/3.0 Result
Command: /bin/ls -l /u02/dbmaint/test//test.sh
-rwxr-xr-x 1 db_admin oinstall 247 Dec 3 14:57 /u02/dbmaint/test//test.sh
[db_admin@orawarehs test]$





[db_admin@rhel6-dave test]$ /u02/dbmaint/test/test.sh ### BASH 4.1 results
Command: /bin/ls -l $WORK_DIR/test.sh
/bin/ls: cannot access $WORK_DIR/test.sh: No such file or directory


Top
 Profile  
 PostPosted: Wed Dec 08, 2010 8:50 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
yeah......but the fix is easy enough.

CHANGE THIS
Code:
echo 'Command:'$v_cmd
$v_cmd

exit



TO THIS
Code:
echo 'Command:'$v_cmd
eval $v_cmd

exit


;) Hope that helps.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP