I have a text file I am trying to read into an Array using Bash. Here are the contents of text file:
Vol12
Vol0
Vol2
Vol21
I want to extract the number from the above string and present it to the user to select the number to enter choice such:
12 - Vol12
0 - Vol0
2 - Vol2
21 - Vol21
User would enter 12 to select Vol12 or 2 to select Vol2 and use the selection to do further action.
I have been searching how to do this but here is what I have so far:
Vol="/Users/alex/Downloads/file.txt"
options=($(tail -n+1 $Vol | awk '{print $1}' | sort | uniq) All Quit)
for (( i = 0; i < ${#options[@]}; i++ )); do
echo "$i - ${options[i]}"
done
echo -e "Enter number corresponding to the Volume snapshot you want to restore: \n"
read vol
}
Following output is what I am getting with above code:
OPTIONS MENU
0 - Vol12
1 - Vol0
2 - Vol2
3 - Vol21
4 - All
5 - Quit
Enter number corresponding to the Volume snapshot you want to restore:
How can I get the output to show like following and able to select 12 or 0 ?
12 - Vol12
0 - Vol0
2 - Vol2
21 - Vol21
Please help