Overwrite a Source Script Variable Value


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Overwrite a Source Script Variable Value
# 1  
Old 06-13-2013
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}"

# 2  
Old 06-14-2013
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}"

This User Gave Thanks to Don Cragun For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Source functions from variable

so i found a way to do this. #!/bin/bash MYF=$(/home/jason/myfunctions) source <(printf '%s\n' "${MYF}") echo "${var1}" /home/jason/myfunctions is a script that outputs information..i.e. functions...etc that needs to be sourced. I have no control over /home/jason/myfunctions. i can... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

Source functions from variable

I have a functions file containing functions: file.functions: myTest () { echo "MYPWD=$(echo $(pwd))" echo "MYLOGNAME=${LOGNAME}" } myCar () { echo "MYDATE=$(date)" echo "MYUPTIME=$(uptime)" } i know i can source this file in another script using something similar to this: source... (8 Replies)
Discussion started by: SkySmart
8 Replies

3. Shell Programming and Scripting

Script to overwrite & before that keep copy a file on many servers

I have ssh password less auth enable & script does the job well as well #/bin/bash for i in `cat ip` do scp /etc/resolv.conf root@$ip done But I need to take backup of the file i will overwrite .. is there any simple way ? Kindly respond (5 Replies)
Discussion started by: heman96
5 Replies

4. Shell Programming and Scripting

Shell script to overwrite a file

Hi Guys, My requirement as follows, i want to write a shell script to display the files of a folder, i export it to a file to mail the file. The problem is the exported file is getting appended every time I run the script. I just want the file to be over written. can anyone suggest?? ... (4 Replies)
Discussion started by: Karthick N
4 Replies

5. Shell Programming and Scripting

Need to overwrite shell script using vi editor

I have an existing shell script that I am trying to modify. I have about 10 lines of info I want to overwrite using text someone emailed to me. I guess what I am trying to do basically is like a copy/paste, but it's not working for me. I am using Cygwin and vi editor. I open the script and... (4 Replies)
Discussion started by: kimberlyg2007
4 Replies

6. Shell Programming and Scripting

Source environment variable in script

Hi, I construct a bash script to finish some tasks. One of the task is to set up some environment variables. There is already one script file to complete the environment variables setting work. I am not able to know the detail of how to set these variables. So, I may just need to call this... (4 Replies)
Discussion started by: gofortime
4 Replies

7. Shell Programming and Scripting

how to source csh script in tcl script

i have atcl script and i want to source a csh script to reflect changes done by script ........ Please help....... (0 Replies)
Discussion started by: paragarora47
0 Replies

8. Shell Programming and Scripting

Overwrite a running shell script

Hello all, This might be a dumb question...but i am running into this situation. I have a shell script that is currently in running state. It has big sql's in it and will run for few days. What happens if I change the shell now? Eg: a.shl is running and i want to mv b.shl a.shl I... (5 Replies)
Discussion started by: gsjdrr
5 Replies

9. Shell Programming and Scripting

a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all, i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ... specifically, i'd like to: (1) specify a src directory (2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs (3) clone that same, empty dir hierarchy to... (2 Replies)
Discussion started by: OpenMacNews
2 Replies
Login or Register to Ask a Question