pdathu
October 13, 2011, 6:26pm
1
Hi All,
I have one variable "TABLE_LIST" having the values and each valeus i can run in for loop like below:
TABLE_LIST= abc,abcd,acbfd
i should write the for loop and use each value at a time .
Please help me
Thanking in advance ..............
Regards,
Dathu
You can make it split on "," by changing the special IFS variable:
VAR="a,b,c,d,e"
OLDIFS="$IFS"
IFS=","
for V in $VAR
do
echo $V
done
IFS="$OLDIFS"
pdathu
October 13, 2011, 6:45pm
3
i didn't understand ur code. Why yor are using OLDIFS.
Can i write code the below:
for EACH_TEBLE in $TABLE_LIST
do
if [[ EACH_TEBLE == "abc"]] then
......
elif [[ EACH_TEBLE == "abcd"]] then
......
else .....
done
The above code is correct?
OLDIFS is used to keep the original IFS, and roll it back after run the script.
So you can set the special variable IFS to what it used to be before you changed it. It defaults to any whitespace. Changing it to "," lets you split on "," instead, like the ,'s in your string.
Can i write code the below:
for EACH_TEBLE in $TABLE_LIST
do
if [[ EACH_TEBLE == "abc"]] then
......
elif [[ EACH_TEBLE == "abcd"]] then
......
else .....
done
The above code is correct?
It won't work without setting IFS="," first. That's what causes it to split $TABLE_LIST instead of considering it one big string.