Breaking News
You are here: Home / Tag Archives: unix programs

Tag Archives: unix programs

Feed Subscription

how to write shell script that will add two nos, which are supplied as command line argument, and if this two no’s are not given show error and its usage

how to write shell script that will add two nos, which are supplied as command line argument, and if this two no’s are not given show error and its usage

if [ $# -ne 2 ] then echo "Usage - $0 x y" echo " Where x and y are two nos for which I will print sum" exit 1 fi echo "Sum of $1 and $2 is `expr $1 + $2`" Read More »

write script to find out biggest number from given three nos. nos are supplies as command line argument. print error if sufficient arguments are not supplied

write script to find out biggest number from given three nos. nos are supplies as command line argument. print error if sufficient arguments are not supplied

if [ $# -ne 3 ] then echo "$0: number1 number2 number3 are not given" >&2 exit 1 fi n1=$1 n2=$2 n3=$3 if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ] then echo "$n1 is Bigest number" elif [ $n2 -gt $n1 ] && [ $n2 -gt $n3 ] then echo "$n2 is Bigest number" elif [ ... Read More »

write script, using case statement to perform basic math operation

write script, using case statement to perform basic math operation

Write Script, using case statement to perform basic math operation as follows + addition – subtraction x multiplication / division The name of script must be ‘q4’ which works as follows $ ./q4 20 / 3, Also check for sufficient command line arguments   if test $# = 3 then case $2 in +) let z=$1+$3;; -) let z=$1-$3;; /) let ... Read More »

write script to print given number in reverse order, for eg. if no is 123 it must print as 321.

write script to print given number in reverse order, for eg. if no is 123 it must print as 321.

if [ $# -ne 1 ] then echo "Usage: $0 number" echo " I will find reverse of given number" echo " For eg. $0 123, I will print 321" exit 1 fi n=$1 rev=0 sd=0 while [ $n -gt 0 ] do sd=`expr $n % 10` rev=`expr $rev \* 10 + $sd` n=`expr $n / 10` done echo "Reverse ... Read More »

write script to determine whether given command line argument ($1) contains “*” symbol or not, if $1 does not contains “*” symbol add it to $1, otherwise show message “symbol is not required”. for e.g. if we called this script q12 then after giving , $ q12 /bin here $1 is /bin, it should check whether “*” symbol is present or not if not it should print required i.e. /bin/*, and if symbol present then symbol is not required must be printed. test your script as $ q12 /bin $ q12 /bin/*

write script to determine whether given command line argument ($1) contains “*” symbol or not, if $1 does not contains “*” symbol add it to $1, otherwise show message “symbol is not required”. for e.g. if we called this script q12 then after giving , $ q12 /bin here $1 is /bin, it should check whether “*” symbol is present or not if not it should print required i.e. /bin/*, and if symbol present then symbol is not required must be printed. test your script as $ q12 /bin $ q12 /bin/*

cat "$1" > /tmp/file.$$ 2>/tmp/file0.$$ grep "*" /tmp/file.$$ >/tmp/file0.$$ if [ $? -eq 1 ] then echo "Required i.e. $1/*" else echo "Symbol is Not required" fi rm -f /tmp/file.$$ rm -f /tmp/file0.$$ Read More »

write script to print contains of file from given line number to next given number of lines. for e.g. if we called this script as q13 and run as $ Q13 5 5 myf , Here print contains of ‘myf’ file from line number 5 to next 5 line of that file

write script to print contains of file from given line number to next given number of lines. for e.g. if we called this script as q13 and run as $ Q13 5 5 myf , Here print contains of ‘myf’ file from line number 5 to next 5 line of that file

if [ $# -eq 0 ] then echo "$0:Error command arguments missing!" echo "Usage: $0 start_line uptoline filename" echo "Where start_line is line number from which you would like to print file" echo "uptoline is line number upto which would like to print" echo "For eg. $0 5 5 myfile" echo "Here from myfile total 5 lines printed starting from ... Read More »

Scroll To Top