Overwrite a Source Script Variable Value | Unix Linux Forums | UNIX for Dummies Questions & Answers

  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 Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-13-2013
Ariean Ariean is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 22 October 2014, 11:48 AM EDT
Posts: 227
Thanks: 77
Thanked 2 Times in 2 Posts
Overwrite a Source Script Variable Value

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

Sourced Script:

Code:
GEN_PARAM_LIST4=""$LOG_DIR"/dwh_GenerateXMLFile.lst"
GEN_PARAM_LIST4_v2=""$LOG_DIR"/dwh_GenerateXMLFile.v2.lst"

I am using below statement for replacing.
Script2:

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

Error:

Code:
/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.


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

Sponsored Links
    #2  
Old 06-14-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 18 December 2014, 12:08 AM EST
Location: San Jose, CA, USA
Posts: 5,245
Thanks: 205
Thanked 1,751 Times in 1,491 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:

Code:
[ ! -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:

Code:
[ ! -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 Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:37 AM.