This is a discussion on Variables scope within the Shell scripting forums, part of the Development/Scripting category; Hi! I have a problem with variables scope. Firstly, a little code... There's a loop in the loop: Code: echo ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
Hi!
I have a problem with variables scope. Firstly, a little code... There's a loop in the loop: Code:
echo `gsh list_eq all > $TEMP`
while read line
do
SHELF=`echo $line | awk '{ print $1 }'`
SLOT=`echo $line | awk '{ print $2 }'`
echo `gsh get_eq_info -eq { $SHELF $SLOT } > $TEMP1`
egrep "ProdName|ProdNo|Revision|SerialNo" $TEMP1 > $TEMP2
while read line
do
PAR=`echo $line | awk '{ print $1 }'`
VAL=`echo $line | awk '{ print $3 $4 $5 }'`
if [ "$PAR" = "ProdName" ]; then
PRODNAME=$VAL
echo $PRODNAME
elif [ "$PAR" = "ProdNo" ]; then
PRODNO=$VAL
echo $PRODNO
elif [ "$PAR" = "Revision" ]; then
REV=$VAL
echo $REV
else
SERIALNO=$VAL
echo $SERIALNO
fi
done < $TEMP2
echo "$SHELF $SLOT;$PRODNAME;$PRODNO;$REV;$SERIALNO;"
done < $TEMP
Code:
echo "$SHELF $SLOT;$PRODNAME;$PRODNO;$REV;$SERIALNO;" Code:
1 1;;;;; The problem is I have to place all the params in one line, because (as mentioned above), I need them in CSV file. When I write them directly to the file, every param is placed in next line and this is not an option. Does anyone has an idea?! Thanks is advanced... -- Rgds fahur |
| Sponsored Links | ||
|
|
|
|||
|
initialize variables before starting while loop
Code:
SHELF="" SLOT="" PRODNAME="" PRODNO="" REV="" SERIALNO="" # start while loop ,,,, ,..... .. Code:
VAL=`echo $line | awk '{ print $3 $4 $5 }'`
Code:
bash -x ./script-name |
|
|||
|
Quote:
Quote:
-- Rgds fahur |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Fold Command with variables | Wannabee | Shell scripting | 1 | 09-27-2007 04:28 AM |
| Linux set environment variables in my shell | chiku | Shell scripting | 1 | 12-30-2006 05:05 AM |