Article 55GQH [SOLVED] Bash Script to Create Menu Based on a File List (Map Files List to Numbers)

[SOLVED] Bash Script to Create Menu Based on a File List (Map Files List to Numbers)

by
Steve R.
from LinuxQuestions.org on (#55GQH)
As part of learning bash scripting, I developed a bash script to undertake an incremental back-up. The next question, was how to obtain a list of the back-up files and to select one (tar) archive file for listing all the files stored in that (tar) archive.

I found the solution here: Create bash menu based on file list (map files to numbers). It ran "right-out-of-the-box" with only obvious minimal tweaking. Seemed well worth re-posting here. See the answer on Ask Ubuntu to get full context. Credit goes to: deltab.

Code:echo "The following `*.war` archives were found; select one:"

# set the prompt used by select, replacing "#?"
PS3="Use number to select a file or 'stop' to cancel: "

# allow the user to choose a file
select filename in *.war
do
# leave the loop if the user says 'stop'
if [[ "$REPLY" == stop ]]; then break; fi

# complain if no file was selected, and loop to ask again
if [[ "$filename" == "" ]]
then
echo "'$REPLY' is not a valid number"
continue
fi

# now we can use the selected file
echo "$filename installed"

# it'll ask for another unless we leave the loop
break
donelatest?d=yIl2AUoC8zA latest?i=pRh1mLdBQCM:fkLBBexISb4:F7zBnMy latest?i=pRh1mLdBQCM:fkLBBexISb4:V_sGLiP latest?d=qj6IDK7rITs latest?i=pRh1mLdBQCM:fkLBBexISb4:gIN9vFwpRh1mLdBQCM
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments