mercredi 21 février 2018

loop case statement without exit the shell script

I have a simple shell script to select diff task and perform it. If option 1 is selected it performs that task and it quits the script.

But What I wanted the script to wait for the user to input for another task and perform it until user exit manually.

say first the user selects option 1 and he gets the output. Next, the user wants to select option 2 and should get the output. until he quits the script manually.

#!/bin/sh
echo "For Fruits [1] "
echo "For Vegetables [2] "
echo "For drinks [3] "
read output
case $output in 
1)
cat 1.txt | tr , '\n' | sort >epackP.txt 
cat 2.txt | tr " " '\n'| /usr/xpg4/bin/awk -F "T000" '{print $2}'|/usr/xpg4/bin/awk -F "+" '{print $1}'|sed '/^$/d' | sort >symmP.txt
diff -ibw 1.txt 2.txt
if [ $? -eq 0 ]; then
   echo "********** Files matched :D **********"  
else
   echo "********** Mismatch found :( **********"
 fi
;;
2)
cat 3.txt | tr , '\n' | sort >epackP.txt 
cat 4.txt | tr " " '\n'| /usr/xpg4/bin/awk -F "T00" '{print $2}'|/usr/xpg4/bin/awk -F "+" '{print $1}'|sed '/^$/d' | sort >symmP.txt
diff -ibw 3.txt 4.txt
if [ $? -eq 0 ]; then
   echo "********** Files matched :D **********"  
else
   echo "********** Mismatch found :( **********"
fi
;;
3)
diff -ibw 5.txt 6.txt 
if [ $? -eq 0 ]; then
   echo "********** Files matched :D **********"  
else
   echo "********** Mismatch found :( **********"
 fi
   ;;
*)
echo "retry"
esac

Aucun commentaire:

Enregistrer un commentaire