I'm really new in bash scripting and I'm currently automating my project creation process.
I've done a lot of work right now but i'm thinking about changing my installation plugins part... Could someone take a look at this script that I've found on serverfault and modified with my needs, but I don't really understand the whole process... If someone could point me a place where I can learn it or maybe comment this code for me...
Thank you in advance, i'll modify the code on my own after understanding it.
#!/bin/bash
# customize with your own.
options=("advanced-custom-fields-pro" "analytics360" "better-wp-security" "debug-bar" "debug-bar-console" "debug-bar-cron" "email-address-encoder" "force-regenerate-thumbnails" "gravityforms" "gravityforms-multilingual" "hansel-gretel" "log-deprecated-notices" "log-deprecated-notices-extender" "maintenance" "Maintenance-pro" "mshare" "post-duplicator" "responsive-lightbox" "sitepress-multilingual-cms" "what-the-file" "wordpress-seo" "wp-realtime-sitemap" "Exit")
menu() {
echo -e "\033[1mPlease select the plugin you want to install :\033[0m"
for i in ${!options[@]}; do
printf "%3d%s) %s\n" $((i+1)) "${choices[i]:- }" "${options[i]}"
done
[[ "$msg" ]] && echo "$msg"; :
}
prompt="Enter the digit representing the plugin you need : "
while menu && read -rp "$prompt" num && [[ "$num" ]]; do
[[ "$num" != *[![:digit:]]* ]] &&
(( num > 0 && num <= ${#options[@]} )) ||
{ msg="Invalid option: $num"; continue; }
((num--)); msg="${options[num]} was ${choices[num]:+un}checked"
[[ "${choices[num]}" ]] && choices[num]="" || choices[num]="+"
done
printf "You selected"; msg=" nothing"
for i in ${!options[@]}; do
[[ "${choices[i]}" ]] && { printf " %s" "${options[i]}"; msg=""; }
done
echo "$msg"
This code right now only told which option have been selected and display a + in front of the choice when it has been selected and remove the + when it called again... What I need is to add the + when selected, and don't allow the user to use it again, then when selected it has to launch another function with the selection name in parameter.
Thank you for your help I really appreciate, and like I already told, i'm really up to do it myself if someone point me the right doc to read, and if possible comment out this script.
dialog. It's packaged for most GNU/Linux distributions.