Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

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
1 year 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