Professional Documents
Culture Documents
Ques 2: Design a shell script to print the comment “number is negative” if a number
entered by a user is less than 0, to print “number is positive”if number is greater
than 0 otherwise “number entered is 0”.
Try above script as follows:
$ chmod 755 elf
$ ./elf 1
$ ./elf -2
$ ./elf 0
$ ./elf a
and then explain its output.
Ques 3: Execute the following script and note down its drawbacks:
echo -n "Enter a number between 1 and 3 inclusive > "
read character
if [ "$character" = "1" ]; then
echo "You entered one."
else
if [ "$character" = "2" ]; then
echo "You entered two."
else
if [ "$character" = "3" ]; then
echo "You entered three."
else
echo "You did not enter a number"
echo "between 1 and 3."
fi
fi
fi
Ques 4: Design a shell script that identifies whether a user has entered a digit or a
letter and reflects back the same to the standard output.
Ques 7: Construct a shell script to obtain the following pattern on the screen:
Ques 8: Parse the output of the following code in a shell script
while [ $# -ge 1 ]; do
case $1 in
-c*) rate=`echo $1 | cut -c3-`;;
-c) shift; rate=$1 ;;
-p*) prefix=`echo $1 | cut -c3-`;;
-p) shift; prefix=$1 ;;
-*) echo $Usage; exit 1 ;;
*) disks=$*; break ;;
esac
shift
done