Unix/Linux Go Back    

UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Overwrite a Source Script Variable Value

UNIX for Dummies Questions & Answers

Closed Linux or Unix Question    
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 October 2015, 10:25 AM EDT
Posts: 236
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 online now Forum Staff  
Join Date: Jul 2012
Last Activity: 26 November 2015, 4:09 PM EST
Location: San Jose, CA, USA
Posts: 7,670
Thanks: 327
Thanked 2,514 Times in 2,164 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
Closed Linux or Unix Question

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 03:31 PM
Source environment variable in script gofortime Shell Programming and Scripting 4 07-19-2011 08:25 AM
Overwrite a running shell script gsjdrr Shell Programming and Scripting 5 02-18-2010 11:20 AM
a script to clone a dir tree, & overwrite the dir struct elsewhere? OpenMacNews Shell Programming and Scripting 2 11-19-2005 02:20 PM
Overwrite Duckman UNIX for Dummies Questions & Answers 9 03-27-2001 01:27 AM

All times are GMT -4. The time now is 05:23 PM.