[SOLVED] Simple bash script allow me to select only 1 from the list
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Simple bash script allow me to select only 1 from the list
Hello
I am trying to create a backup script and i am using this:
Code:
Please select to which backup date [D-M-Y] you want to restore [1, 2, 3 e.t.c]:"
# get the folders count
count=$(ls -1td /home/nginx/domains/*/ | wc -l)
select domainbackupdate in $(ls -1td /backup/${domaintorestore}/*/ | awk -F/ '{print $(NF-1)}'); do
# if input is a number and is less than or equal to count
if (( $REPLY && $REPLY <= $count )) 2> /dev/null; then
break
else
echo "Your input ${REPLY} is not available. Please select a number from the list:"
fi
done
For your script to work count has to equal the number of directories in /backup/${domaintorestore} not /home/nginx/domains/*/. If you want to select domain to restore your asking the wrong question.
What michaelk said...$count is the count of domains, not the count of available backups. So when you test against $count, only 1 is allowed.
Reset $count (or use another variable) to contain the number of available backups.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.