Saturday, April 2, 2011

SHELL SCRIPT TO SORT IN DESCENDING ORDER THE NUMBERS GIVEN AS SHELL ARGUMENTS


if [ $# -eq 0 ]
then
    echo "Enter valid Arguments"
    exit
fi

> temp

for i in $*
do
echo "$i" >> temp
done

echo "Your sorted data:"
sort -nr temp
echo "End of Script"

Output
sh sort 12 20 9 8 17
Your sorted data :
8 9 12 17 20

Create Chess Board Using Nested For loop in UNIX SHELL SCRIPT


for (( i = 1; i <= 9; i++ )) ### Outer for loop ###
do
   for (( j = 1 ; j <= 9; j++ )) ### Inner for loop ###
   do
        tot=`expr $i + $j`
        tmp=`expr $tot % 2`
        if [ $tmp -eq 0 ]; then
            echo -e -n "\033[47m "
        else
            echo -e -n "\033[40m "
        fi
  done
 echo -e -n "\033[40m" #### set back background colour to black
 echo "" #### print the new line ###
done

output :~

Tuesday, March 29, 2011

Digital CLOCK on your Screen Using Unix


echo
echo "Digital Clock for unix"
echo "To stop this clock use command kill pid see above for pid"
echo "Press a key to continue. . ."

while :
do
    ti=`date +"%r"`     
    echo -e -n "\033[7s"    
#save current screen postion & attributes

    tput cup 0 69         
# row 0 and column69 is used to show clock


    echo -n $ti           
# put clock on screen

    echo -e -n "\033[8u"   
#restore current screen postion & attributs

    sleep 1
done