amalgamating bash code blocks to give choices -


i have 2 blocks of bash-code want amalgamate. first checks see if have "get-iplayer/get_iplayer" installed , if not prompts installed -

if [[ -x "/usr/bin/get-iplayer" ]] player="/usr/bin/get-iplayer" elif [[ -x "/usr/bin/get_iplayer" ]]  player="/usr/bin/get_iplayer" elif [[ -x "/usr/local/bin/get_iplayer" ]] player="/usr/local/bin/get_iplayer" else echo "$0: error: 'get-iplayer' or 'get_iplayer' not installed. please install it." >&2  exit 1 fi 

i want add in ability choose 1 use, have 3 of them installed want use 1 @ /usr/local/bin, -

{     read -n1 -p "$(tput setaf 5)             get-iplayer = a,             get_iplayer = b,             new get_iplayer = c,             quit = q? [a/b/c/q] " abcq     echo; echo "$(date +%y-%m-%d\ %h:%m:%s) answer: $abcq" >> $log    case "$abcq" in         [a]* ) /usr/bin/get-iplayer & echo;;         [b]* ) /usr/bin/get_iplayer & echo;;         [c]* ) /usr/local/bin/get_iplayer & echo;;             [q]* ) echo; exit;;         * )      esac  } 

but how can please? i've been sitting here trying puzzle out, not getting anywhere.

you must able see choosing, must called "player" variable-name in rest of script.

use array hold existing executables, little-used select command choose:

iplayers=() possible in /usr/bin/get-iplayer /usr/bin/get_iplayer /usr/local/bin/get_iplayer;     [[ -x $possible ]] && iplayers+=("$possible") done if (( ${#iplayers[@]} == 0 ));     echo "$0: error: 'get-iplayer' or 'get_iplayer' not installed. please install it." >&2     exit 1 fi  ps3="select iplayer: " select choice in "${iplayers[@]}";     [[ -n $choice ]] && break done  echo "you chose: $choice" 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -