Question on variable inheritance & code statements


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Question on variable inheritance & code statements
# 1  
Old 01-15-2010
Question on variable inheritance & code statements

1) I have the below code in concattxnrecords.sh shell script and it is calling the genericVars.sh shell script which is mentioned as below has some code inside it which would intialize some variables in it, now my question is will this shell script would inherit those variable definitions or not though it is commented out? I just got confused with my understanding on "#!/bin/ksh" & "#. $HOME/bin/scripts/generic/genericVars.sh"

concattxnrecords.sh
Code:
#!/bin/ksh
###################################################################
#
#  concatDACRecs.sh
#  
#  Place to hold all common validate functions
###################################################################
#set -x
#. $HOME/bin/scripts/generic/genericVars.sh


genericVars.sh
Code:
#!/bin/ksh
###################################################################
#
#  genericVars.sh
#
#  11/30/2006
#  Hold common variables in once place to it is easy to change across
#  the board if and when needed.
#
###################################################################

# generic variables
GEN_SCRIPTS=$HOME/bin/scripts/generic
PRE_V_SCRIPTS=$HOME/bin/scripts/prevalidator
LAUNCH_SCRIPTS=$HOME/bin/scripts/launcher
TSTFILES_DIR=$GEN_SCRIPTS/tstfiles
LOCKFILES_DIR=$GEN_SCRIPTS/lockfiles
LOG_DIR=$HOME/bin/scripts/logs
DAC_POST_SCRIPT=/product/apps/informatica/v7/pc/ExtProc/NewScripts/postprocess/DAC
# Watcher vars
FW_POLL_INTERVAL=60
POLL_INTERVAL=30

# Informatica vars
INFA_HOME=/product/apps/informatica/v7
INFA_SVR_HOME=$INFA_HOME/pc
INFA_REPSVR_HOME=$INFA_HOME/repserver
INFA_HOST=$HOST
INFA_PORT=4001
INFA_EXEC_USER=sete_operator
INFA_EXEC_PASS=sete_operator

2) May i know what is the below code doing, specifically i didn't understand the "if [[ ! -z $MKT_VALUE_FLD ]]" and "shift;" statements in the below code

Code:
until [[ $# -eq 0 ]]
do
     NAME=`basename $1`
     MKT_VALUE_FLD=`grep $NAME $DAC_POST_SCRIPT/TT_DAC_Ctrl_total.map | cut -f2 -d'|'`
     if [[ ! -z $MKT_VALUE_FLD ]]
     then
           echo $1 >> $DAC_POST_SCRIPT/allMktValue.tmp
           cat $1 |  cut -f$MKT_VALUE_FLD -d'^' >> $DAC_POST_SCRIPT/allMktValue.tmp
      fi;
      shift;
done;

3) May i also know what are the below statements are doing
Code:
echo "`cat $DAC_POST_SCRIPT/DAC_CONTROL_TOTAL.txt`^999999999999^$COUNTER" >> $OUTPUT_FILE.out

> `head -1 /product/apps/informatica/v7/pc/TgtFiles/NEW_DAC/DAC_TXN_header.out |cut -f2 -d^ | sed -e 's/txt/flg/'`

Many Thanks,
Regards,
Ariean
# 2  
Old 01-15-2010
1) the values of variables defines in $HOME/bin/scripts/generic/genericVars.sh will be available in concattxnrecords.sh
2)
Code:
[[ ! -z $MKT_VALUE_FLD ]]

is the same as
Code:
if ! test -z $MKT_VALUE_FLD # if the value of the variable MKT_VALUE_FLD
                           # has no zero length

3)
Code:
echo "`cat $DAC_POST_SCRIPT/DAC_CONTROL_TOTAL.txt`^999999999999^$COUNTER"

The content of the file "$DAC_POST_SCRIPT/DAC_CONTROL_TOTAL.txt" will be placed instead of
Code:
`cat $DAC_POST_SCRIPT/DAC_CONTROL_TOTAL.txt'

, so the final result you will get is :
the content of file $DAC_POST_SCRIPT/DAC_CONTROL_TOTAL.txt joined with string "^999999999999^$COUNTER" altogether stored at the end of the file $OUTPUT_FILE.out

Code:
> `head -1 /product/apps/informatica/v7/pc/TgtFiles/NEW_DAC/DAC_TXN_header.out |cut -f2 -d^ | sed -e 's/txt/flg/'`

`head -1' will read the 1-st line of the file DAC_TXN_header.out ;
`cut' will extract the 2-nd field of the input line assumed that `^' sign is the field delimiter;
`sed -e 's/txt/flg/'' as far as I know sed will replace the substring `txt' with the substring `flg'
# 3  
Old 01-15-2010
Thanks for your reply

1) But the code has been commented out right, how could it would inherit those variables.

Code:
#. $HOME/bin/scripts/generic/genericVars.sh

# 4  
Old 01-18-2010
of course if it is commented it won't be read in. I thought the line had been active , but you had commented it out and pasted it here.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

What is wrong with below python inheritance code?

I am using python 3.4. Below is the exception I am getting- Traceback (most recent call last): File "./oop.py", line 20, in <module> y = DerivedClass("Manu") File "./oop.py", line 15, in __init__ super().__init__(self,value) TypeError: __init__() takes 2 positional arguments but... (2 Replies)
Discussion started by: Tanu
2 Replies

2. Shell Programming and Scripting

Searching for pattern in variable using case statements

i would like to search a variable for a pattern, without having make any calls to external tools. i have a code like this: COUNTPRO2="gine is very bad vine is pretty good" case "${COUNTPRO2}" in *vine*) factor=${COUNTPRO2} echo $factor ;; esac If the variable contains... (7 Replies)
Discussion started by: SkySmart
7 Replies

3. Programming

Removing goto statements in FORTRAN code

I have the code below and I want to remove the "go to" statements. Any idea how I can do it? if (iorder == 0) then tmincurrent = 1.0e11 if(ireverse == 0 .or. istop /= 1) then do i = 1, 6 if ((side(i) /= sidelimit(i)) .and. (tminside(i) < tmincurrent)) then ... (1 Reply)
Discussion started by: kristinu
1 Replies

4. Programming

Difference in multiple inheritance and multilevel inheritance: same method name ambiguity problem

Hi, In multi-level inheritance: class A { public: void fun() { cout << "A" << endl; } }; class B : public A { public: void fun() { cout << "A" << endl; } }; class C : public B { }; int main() { C c; c.fun(); // Ans: A } (1 Reply)
Discussion started by: royalibrahim
1 Replies

5. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

6. Shell Programming and Scripting

syntax question in regards to nested awk statements

Hello all, I am writing up an input file and I was hoping I could get some guidance as to how to best consolidate these 2 awk statements for 1 while loop. Here's my input file # cat databases.lst #NOTE: These entries are delimited by tabs "\t" #oracleSID name/pass # db11 ... (2 Replies)
Discussion started by: Keepcase
2 Replies

7. Shell Programming and Scripting

Nested if statements with && and ||?

Hello, I'm a shell scripting noob and new to this forum as well. My question is can nested if statements be done with && and || instead and if it can be done can someone provide an example pls. Thanks in advance for the help (1 Reply)
Discussion started by: zomgshellscript
1 Replies

8. UNIX for Dummies Questions & Answers

Handling return & exit statements

I have 2 shell scripts the primary one would load the other one which will have functions defined in it. Script 1: . /apps/bin/Script 2 function if then continue... .... fi Script 2: function() (10 Replies)
Discussion started by: Ariean
10 Replies

9. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

10. Shell Programming and Scripting

perl - variable inheritance

Hey Everyone, Does anyone know how - or if it's even possible - for a child perl script to inherit the variables of a parent perl script? In a shell script, you would use "export" for example. I am running Perl 5.8. Basically, let's say "perl1.pl" calls "perl2.pl" and I want "perl2.pl" to... (2 Replies)
Discussion started by: gsatch
2 Replies
Login or Register to Ask a Question