Shell Scripting Tutorials: Function


find_average() 
{
	sum=0
	i=1
	len=$#
	x=$((len + 1))
	while [ $i -lt $x ]
	do
		arg=${!i}
		sum=$((sum + arg))
		i=$((i + 1 ))
	done
	avg=$((sum / len))
	return $avg
}

find_average 10 20 30 40
echo $?

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
rakesh
rakesh
11 months ago

thanks for sharing shell scripting blogs. keep writing blogs that helps no of software developer

1
0
Would love your thoughts, please comment.x
()
x