Search This Blog

Wednesday, January 21, 2009

linux script using while e.g script for table from one to ten, input from command line

#!/bin/sh
#
#Script == testing while statement
#
#
if [ $# -eq 0 ]
then
echo "Error - Number missing form command line argument"
echo "Syntax : $0 number"
echo "Use to print multiplication table for given number"
exit 1
fi

# $1 is first command line argument
n=$1

i=1
while [ $i -le 10 ]
do
echo "$n * $i = `expr $i \* $n`"
#or use bc command
#echo "$n * $i = `echo $i*$n | bc`"
i=`expr $i + 1`
#or
# i=$(($i+1))
done

No comments:

Post a Comment