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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I export a variable to a shell script

Status
Not open for further replies.

g00se

Technical User
Jul 5, 2000
4
US
I am using an awk command inside a shell script that uses the split() function.&nbsp;&nbsp;I want to export that array to the shell script so I can use it.&nbsp;&nbsp;See script below:<br><br>#!/usr/bin/ksh<br><br>#set -x<br>&nbsp;<br>baseDir=&quot;/work/&quot;<br>fName=${baseDir}$1<br>beginDate=`head -1 ${fName} ¦ cut -d &quot; &quot; -f4 ¦ sed -e 's./.:.g' -e 's/\[//' `<br>endDate=`tail -1 ${fName} ¦ cut -d &quot; &quot; -f4 ¦ sed -e 's./.:.g' -e 's/\[//' `<br>&nbsp;<br>echo $beginDate ¦ awk ' { split($1, var, &quot;:&quot;) } { print $1 } { print var[2] } '<br>echo &quot;var[2] = ${var[2]}&quot;<br><br>When I try to display the contents of var[anything] it is blank.&nbsp;&nbsp;Any ideas?<br><br><br>-Eric
 
Hi,<br><br>Try <br>var2=`echo $beginDate ¦ awk ' { split($1, var, &quot;:&quot;) } { print $1 } { print var[2] }'`<br><br>HTH,<br>Ravi...<br><br>
 
Eric,<br>had time to look now.<br>As Ravi pointed out you need to encapsulate the whole command in `` quotes and assign it to var2. This will ensure that the command wil run and only the output will be assigned to the variable.<br>Another option is to echo the lot to a file so you have a hard copy i.e.<br><br>echo 'var[2] = '`$beginDate ¦ awk ' { split($1, var, &quot;:&quot;) } { print $1 } { print var[2] } '` &gt; result.file<br><br> <p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top