Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a variable to another shell script 1

Status
Not open for further replies.

jpor

Technical User
Nov 29, 2000
212
GB
Hi guys,

I know this has been covered quite a bit. But I feel this is a different situation.

I am basically running a KSH buy it runs a couple ISQL (Informix SQL) scripts inside. But If I use a case loop for choosing 1 or 2 to either change a database or not I get errors on the longs of line # '<' not equal. E.g I am running a command as of: isql -s >> /tmp/log.log << EOF But to end each line of a ISQL update you have to use ; to end each paragragh. BUt as you are well aware in a case statement you use ;; and esac. What I am attempting is to pass the job number variable to 2 other scripts that seperately run the updates.

Here is the code I am using to get the variable:

echo &quot; &quot;
echo &quot; &quot;
echo &quot; &quot;
echo &quot; Enter Customers Job Number :\t\c &quot;; read jno
echo &quot; &quot;

What I want to do next in my choose statement is this:

/usr/cs3/scripts/estupd.sc &quot;$jno&quot;

And then the shell script at the other end will then read in the $jno variable.

Any ideas ?

Thanks in advance

 
Everything is fine in script 1
So in script 2 (/usr/cs3/scripts/estupd.sc )
if you echo $1 - it'll contain the passed parameter ( the job no)

Dickie Bird (:)-)))
 
Thanks Dickiebird.

within the script /usr/cs3/scripts/estupd.sc I am running the following code:

isql -s service >> /tmp/log.log << EOF

update jobsheet set
js_curr_stat_dt = current,
js_est_stat=&quot;40&quot;,
js_est_req=&quot;Y&quot;,
js_curr_stat_code=&quot;05&quot;,
js_eng_suggest=&quot;04&quot;,
js_charge_req=&quot;Y&quot;,
js_charge_stat=&quot;10&quot;

where js_job_no = &quot;$jno&quot;
and js_curr_stat_code = &quot;12&quot;;

insert into jobaudit values
($jno, &quot; &quot;, &quot;12&quot;, &quot; &quot;, CURRENT, CURRENT, &quot;$LOGNAME&quot;);


I have tried using the echo $jno. But I get errors regarding not seeing the $jno within the ISQL. Any ideas ?
 
Use the first (only) passed parameter $1 eg
isql -s service >> /tmp/log.log << EOF

update jobsheet set
js_curr_stat_dt = current,
js_est_stat=&quot;40&quot;,
js_est_req=&quot;Y&quot;,
js_curr_stat_code=&quot;05&quot;,
js_eng_suggest=&quot;04&quot;,
js_charge_req=&quot;Y&quot;,
js_charge_stat=&quot;10&quot;

where js_job_no = $1
and js_curr_stat_code = &quot;12&quot;;

insert into jobaudit values
($1, &quot; &quot;, &quot;12&quot;, &quot; &quot;, CURRENT, CURRENT, &quot;$LOGNAME&quot;);




Dickie Bird (:)-)))
 
Use the export special command before running script 2...

export jno
/usr/cs3/scripts/estupd.sc
 
Thanks guys. Will give that a go.
 
Either way, you may (depending upon your isql) have to
use '${1}' or '${jno}' ( including quotes and braces )

HTH


Dickie Bird (:)-)))
 
Thanks Ygor and Dickiebird. The export jno and the ${jno} did the trick. Just sorting out the SQL.

 
Just a quick question regarding the export command.

Will the export need nulling ? As this program I am devising will be run by more than one person.

Thanks again for your input.
 
export allows the child shell to see the values but in the same session, so
1. if other people are suing one after the another in continuation then they would see the previous result
2. if from different logins simultaneous or not they would see variable value of joe entered by them in that session

hope this clears yoyr doubt



[ponder]
----------------
ur feedback is a very welcome desire
 
So basically after each program that is run in turn. I would need this sort of syntax:

jno = &quot;0&quot;
export jno

?
 
if u quit the program the exported value is no longer vaialbe to its parent shell

presuming u do not have any variable a. (check with env)
Code:
a=1
export a
echo $a

now out of this script
Code:
echo $a
whold result in blank

within the same script
Code:
a=
would unset variable 'a'




[ponder]
----------------
ur feedback is a very welcome desire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top