Skip to main content

Posts

Showing posts with the label Shell Programming

Fibonacci Series generator [Shell Program]

echo "Enter the Number of Terms" read n a = 0 b = 1 count = 1 n1 = `expr $n - 2` if [ $n - eq 1 ] then echo "The Fibonacci series is:" $a elif [ $n - eq 2 ] then echo "The Fibonacci series is:" $a $b else echo "The Fibonacci series is:" echo "$a $b \c" while [ $count - le $n1 ] do c = `expr $a + $b` echo "$c \c" a = $b b = $c count = `expr $count + 1` done fi echo "\n"

Calculator [Shell Program]

clear ans = Y while [ "$ans" = "Y" ] do clear echo "*****MENU*****" echo "1.ADD" echo "2.SUBSTRACT" echo "3.MULTIPLY" echo "4.DIVIDE" echo "5.MOD" echo "0.EXIT" echo "Enter your Choice" read ch case $ch in 1 ) echo "Enter the 1st number"    read num1    echo "Enter the 2nd number"    read num2    s = `expr $num1 + $num2`    echo "The result:" $s ;; 2 ) echo "Enter the 1st number"    read num1    echo "Enter the 2nd number"    read num2    s = `expr $num1 - $num2`    echo "The result:" $s ;; 3 ) echo "Enter the 1st number"    read num1    echo "Enter the 2nd number"    read num2    s = `expr $num1 \* $num2`    echo "The result:" $s ;; 4 ) echo "Enter the 1st number"    read num1    echo "Enter the 2nd number"    read num2    s = `expr $num1 /

Display the Calendar [Shell Program]

clear echo " Enter the Year: \c" read year echo " Enter the Month: \c" read month m = 0 case "$month" in 1 | jan ) m = 1 ;; 2 | feb ) m = 2 ;; 3 | mar ) m = 3 ;; 4 | apr ) m = 4 ;; 5 | may ) m = 5 ;; 6 | jun ) m = 6 ;; 7 | jul ) m = 7 ;; 8 | aug ) m = 8 ;; 9 | sep ) m = 9 ;; 10 | oct ) m = 10 ;; 11 | nov ) m = 11 ;; 12 | dec ) m = 12 ;; *) echo $month   "is not a valid Month! Showing Calendar for " $year ;; esac if [ $m - ne 0 ] then cal $m $year else cal $year fi

Resource Test [Shell Program]

echo "Enter the Resource name" read fname if ( test -s $fname ) then ls -l $fname if ( test -d $fname ) then echo "It is a directory" else echo "It is a file" fi if ( test -r $fname ) then echo "It is a readable" fi if ( test -w $fname ) then echo "It is writable" fi if ( test -x $fname ) then echo "It is executable" fi else echo "No such resource present" fi