This is a simple script program to calculate average of three numbers input as command line arguments.
Important --> UNIX is case sensitive
In scripting
# --> use for insert comments
This is the script avg.sh
#following command indicate the place to interpret the script
#!bin/bash
#$1 $2 and $3 get the command line arguments
echo “First three arguments are $1 $2 $3”
echo “This program is $0”
# $* can use to display all the command line arguments
echo “All arguments : $*”
# $# is used to get the number of arguments
echo “Number of arguments: $#”
# let command is used to execute arithmetic expression
# when declaring a variable that should not put $ sign at the beginning
let sum=$1+$2+$3
#whenever that variable is referring $ sign must put in front of the variable name
echo “sum is $sum”
let avg=$sum/$#
echo “Average is : $avg”
Wednesday, August 6, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment