Unix/Linux Go Back    

UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Overwrite a Source Script Variable Value

UNIX for Dummies Questions & Answers

Thread Tools Search this Thread Display Modes
Old Unix and Linux 06-13-2013
Ariean Ariean is offline
Registered User
Join Date: Apr 2008
Last Activity: 16 July 2017, 10:40 AM EDT
Posts: 237
Thanks: 80
Thanked 3 Times in 3 Posts
Overwrite a Source Script Variable Value

Hello All,
How do i overwrite a sourced script variable value.

Sourced Script:


I am using below statement for replacing.

[ ! -z ${UNINUM} ] && "${GEN_PARAM_LIST4}"="${GEN_PARAM_LIST4_v2}"


/home/infrmtca/bin/dwh_GenerateXMLFile.sh: line 204: /home/infrmtca/bin/log/dwh_GenerateXMLFile.lst=/home/infrmtca/bin/log/dwh_GenerateXMLFile.v2.lst: No such file or directory

---------- Post updated at 05:11 PM ---------- Previous update was at 05:06 PM ----------

I think i got it but not sure if this is right approach.

[ ! -z ${UNINUM} ] && GEN_PARAM_LIST4="${GEN_PARAM_LIST4_v2}"

Sponsored Links
Old Unix and Linux 06-14-2013
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Join Date: Jul 2012
Last Activity: 25 September 2017, 1:05 PM EDT
Location: San Jose, CA, USA
Posts: 10,509
Thanks: 544
Thanked 3,676 Times in 3,136 Posts
It is a correct approach, but you're missing some quotes.

You don't show us how UNINUM is set. As long as you know that UNINUM will either expand to an empty string or to a single word, what you have will probably work. But, it is poor programming practice to have an unquoted string that sometimes expands to an empty string. If $UNINUM happens to expand to more than one word, the test command:

[ ! -z ${UNINUM} ]

could yield a syntax error, true, or false depending on the expansion of $UNINUM. The following replacement seems to do what you want and is a lot safer:

[ ! -z "$UNINUM" ] && GEN_PARAM_LIST4="${GEN_PARAM_LIST4_v2}"

The Following User Says Thank You to Don Cragun For This Useful Post:
Ariean (06-14-2013)
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to overwrite shell script using vi editor kimberlyg2007 Shell Programming and Scripting 4 04-11-2013 02:31 PM
Source environment variable in script gofortime Shell Programming and Scripting 4 07-19-2011 07:25 AM
Overwrite a running shell script gsjdrr Shell Programming and Scripting 5 02-18-2010 10:20 AM
a script to clone a dir tree, & overwrite the dir struct elsewhere? OpenMacNews Shell Programming and Scripting 2 11-19-2005 01:20 PM
Overwrite Duckman UNIX for Dummies Questions & Answers 9 03-27-2001 12:27 AM

All times are GMT -4. The time now is 06:29 PM.