Sunday 27 October 2013

Bash Exercise - 4

Script 16: Select and Execute
#!/bin/bash
echo -e "1) a \n 2) b \n 3) c \n 4) d "
echo "select any one:"
read a
case $a in
a) echo -e "enter either a1 or a2 or a3"
read a1
case $a1 in
a1) echo "one";;
a2) echo "two";;
a3) echo "three";;
esac
;;
b) echo "case two selected";;
c) echo "case three selected";;
esac

Script 17: Firstname & Lastname
echo "enter your first and last names"
read s1 s2
name="$s1 $s2"
echo $name
Script 18: For Do Loop
#!/bin/bash
for i in $( ls )
do
echo item:$i
done
Script 19: For Don't Do Loop
#!/bin/bash
for var1 in `ls `
do
#echo "this is my for loop"
if test -e $var1
then
echo $var1
#mv $var1 b$var1
fi
done
Script 20: For 1
#!/bin/bash
#1 is std o/p
for i in 1
do
a=`wc -l -w< file`
done
echo $a

No comments :

Post a Comment