I would like to get an output based on the input we provided. For Example,
if I selected 1 it should take the 1st element in the array and the output should be My name is test
if I selected 2 it should take the 2nd element in the array and the output should be My name is test1
similarly, if I select all the output should be My name is test
My name is test1
My name is test2
My name is test3
a=("test" "test1" "test2" "test3")
testfunction() {
echo My name is $a
}
echo "Enter a number"
select number in "test" "test1" "test2" "tes3" "all"; do
case "$number" in
test)
testfunction "${a[0]}"; break;;
test1)
testfunction "${a[1]}"; break;;
test2)
testfunction "${a[2]}"; break;;
test3)
testfunction "${a[3]}"; break;;
all)
testfunction "${a[@]}"; break;;
esac
done
Can someone please help me with this?
$numberis numeric and in the correct range, and then calltestfunction "${a[$number]}".