bash select multiple answers at once -
i have flat file called items want populate select want able choose multiple items @ 1 time.
contents of items file:
cat 1 dog 1 pig 1 cherry 2 apple 2 basic script:
#!/bin/bash ps3=$'\n\nselect animals like: ' options=$(grep '1' items|grep -v '^#' |awk '{ print $1 }') select choice in $options echo "you selected: $choice" done exit 0 the way flows can select 1 option @ at time. i'd able answer 1,3 or 1 3 , have respond "you selected: cat pig"
thank you,
tazmarine
you can not such, can record each individual selection:
#!/bin/bash ps3=$'\n\nselect animals like: ' options=$(grep '1' items|grep -v '^#' |awk '{ print $1 }') # array storing user's choices choices=() select choice in $options finished # stop choosing on option [[ $choice = finished ]] && break # append choice array choices+=( "$choice" ) echo "$choice, got it. others?" done # write out each choice printf "you selected following: " choice in "${choices[@]}" printf "%s " "$choice" done printf '\n' exit 0 here's example interaction:
$ ./myscript 1) cat 2) dog 3) pig 4) finished select animals like: 3 pig, got it. others? select animals like: 1 cat, got it. others? select animals like: 4 selected following: pig cat if instead want able write 3 1 on same line, you'll have make own menu loop echo , read
Comments
Post a Comment