70 likes | 305 Views
Shell Script. Exercises. What is the output of?. $ echo " expr 6 + 5“ expr 6 + 5 $ echo ' expr 6 + 5‘ 11. Write Script to see current date, time, username, and current directory. echo "Current date is `date`“ echo "User is $ USER “ echo "Current directory ` pwd `".
E N D
Shell Script Exercises
What is the output of? • $ echo "expr 6 + 5“ • expr 6 + 5 • $ echo 'expr 6 + 5‘ • 11
Write Script to see current date, time, username, and current directory. echo "Current date is `date`“ echo "User is $USER“ echo "Current directory `pwd`"
Write shell script that will add two numbers, which are supplied as command line argument, and if this two numbers are not given show error message. if [ $# -ne 2 ] then echo " Enter 2 number to find the sum“ else echo "Sum of $1 and $2 is `expr $1 + $2`“ fi
Write a shell script to find out biggest number from given three numbers. if [ $# -ne 3 ] then echo “Enter three number to compare them" elif [ $1 -gt $2 ] && [ $1 -gt $3 ] ; then echo "$1 is Bigest number" elif [ $2 -gt $1 ] && [ $2 -gt $3 ] ; then echo "$2 is Bigest number" else echo "$3 is Bigest number" fi
Write a shell script to read a number and find whether the number is odd or even. echo -n “Enter a number : “ read n rem=`expr $n % 2` If [ $rem -eq 0 ] then echo “$n is even number” else echo “$n is odd number” fi