Re: BASH Scripting
Mark Lundy <[email protected]>
| Newsgroups | gmane.linux.redhat.release.enigma |
|---|---|
| Message-ID | <[email protected]> |
Why not just return SIDS?
instead of
echo "SIDS is $SIDS"
use return
return "$SIDS"
and set the output of your grep and pipe to the return value?
# !/bin/sh
#SIDS=""
SIDS=`grep -v '^#' /etc/oratab | while read LINE
do
ISID=`echo $LINE | cut -f1 -d:`
OHOME=`echo $LINE | cut -f2 -d:`
OBOWNER=`ls -l $OHOME/bin/sqlplus | awk '{print $3}'`
SIDS=`echo "$SIDS $OBOWNER:$ISID"`
echo "SIDS is $SIDS"
done`
echo SIDS is $SIDS
echo "OBOWNER is $OBOWNER"
Mark
Pete Peterson wrote:
>>From: Aaron Konstam <[email protected]>
>>To: [email protected]
>>Subject: Re: BASH Scripting
>>
>>On Tue, Mar 18, 2003 at 05:17:08PM -0000, David Nithakorne wrote:
>>
>>
>>>I am trying to set the value of SIDS in the following script to
>>>something other than "". It seems that once out of the do/done block the
>>>value od $SIDS reverts back to ""....why is this and how can I get $SIDS
>>>to keep its new value opnce out of the do/done block.
>>>
>>># !/bin/sh
>>>SIDS=""
>>>grep -v '^#' /etc/oratab | while read LINE
>>>do
>>> ISID=`echo $LINE | cut -f1 -d:`
>>> OHOME=`echo $LINE | cut -f2 -d:`
>>> OBOWNER=`ls -l $OHOME/bin/sqlplus | awk '{print $3}'`
>>> SIDS=`echo "$SIDS $OBOWNER:$ISID"`
>>> echo "SIDS is $SIDS"
>>>done
>>> echo SIDS is $SIDS
>>> echo "OBOWNER is $OBOWNER"
>>>
>>>the /etc/oratab file is: -
>>>
>>>LD4U:/opt/oracle/product/9.2.0:Y
>>>oem:/opt/oracle/product/9.2.0:Y
>>>ld4udev:/opt/oracle/product/9.2.0:Y
>>>
>>>Thanks
>>>
>>>David
>>>
>>>
>>>
>>Just export $SIDS after it is defined.
>>-------------------------------------------
>>Aaron Konstam
>>
>>
>
>How can that work? The export allows referencing the variable
>in the children of the defining process, but the child can't change the
>environment of the parent.
>
>
>