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   -   Original Discussion by Ariean
Ariean Ariean is offline
Registered User
Join Date: Apr 2008
Last Activity: 6 November 2017, 7:11 PM EST
Posts: 240
Thanks: 80
Thanked 4 Times in 4 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   -   Original Discussion by Ariean
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Join Date: Jul 2012
Last Activity: 20 November 2017, 12:28 AM EST
Location: San Jose, CA, USA
Posts: 10,661
Thanks: 572
Thanked 3,734 Times in 3,186 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 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 09:21 AM.