Monday, January 16, 2012

Shell Script to Display numbers Using Array


Q. How to use array in Bash for taking input and displaying it
Ans:

#!/bin/bash
for((i=0;i<5;i++))
do
echo "enter `expr $i + 1` number"
read arr[$i]
done
echo "the numbers you hav entered are"
for((i=0;i<5;i++))
do
echo ${arr[$i]}
done

Output

Enjoy :)

0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.