For a shell script the variable is a table name.
If the table name is test then execute
while IFS=',' read a; do drop.sh $a; done < abc
or else execute
while IFS=',' read a; do create.sh $a; done < abc
How can i achieve this in Linux
For a shell script the variable is a table name.
If the table name is test then execute
while IFS=',' read a; do drop.sh $a; done < abc
or else execute
while IFS=',' read a; do create.sh $a; done < abc
How can i achieve this in Linux
You can use an if - else statement like this;
if [ test ]
then
do something
else
do something else
fi
In your case
if [ "$yourVariable" = "test" ]
then
while IFS=','...
else
while IFS=','...
fi
See here for more, it is bash specific, but mostly usable for other linux shells.
Edit As suggested in the comments, here are some other resources:
test here. By contrast, the POSIX spec for test will apply to all POSIX shells.For multiple conditions of the same type, you can also use the case:
for table in test bla something; do
case "$table" in
test)
echo actions for $table
;;
bla)
echo another actions for $table
;;
*)
echo actions for anything other as test or bla eg for $table
;;
esac
done
output from the above
actions for test
another actions for bla
actions for anything other as test or bla eg for something
e.g. for you case, you could write
table="test"
while IFS=, read -r a; do
case "$table" in
test) drop.sh "$a" ;;
*) create.sh "$a" ;;
esac
done < abc
Some notes:
read -r unless you know why don't want the -r"$a"while read-ing the same abc for the both cases, so DRY (don't repeat yourself) and move the while read... outside of your condition...