snippetbashTip
select — Bash builtin construct for creating menus. More information: <https://www.gnu.org/software/bash/manu
Viewed 0 times
constructselectcommandclibuiltincreatingforbash
Problem
How to use the
select command: Bash builtin construct for creating menus. More information: <https://www.gnu.org/software/bash/manual/bash.html#index-select>.Solution
select — Bash builtin construct for creating menus. More information: <https://www.gnu.org/software/bash/manual/bash.html#index-select>.Create a menu out of individual words:
select {{word}} in {{apple orange pear banana}}; do echo ${{word}}; doneCreate a menu from the output of another command:
select {{line}} in $({{command}}); do echo ${{line}}; doneSpecify the prompt string for
select and create a menu for picking a file or folder from the current directory:PS3="{{Select a file: }}"; select {{file}} in *; do echo ${{file}}; doneCreate a menu from a Bash array:
{{fruits}}=({{apple orange pear banana}}); select {{word}} in ${{{fruits[@]}}}; do echo ${{word}}; doneCode Snippets
Create a menu out of individual words
select {{word}} in {{apple orange pear banana}}; do echo ${{word}}; doneCreate a menu from the output of another command
select {{line}} in $({{command}}); do echo ${{line}}; doneSpecify the prompt string for `select` and create a menu for picking a file or folder from the current directory
PS3="{{Select a file: }}"; select {{file}} in *; do echo ${{file}}; doneCreate a menu from a Bash array
{{fruits}}=({{apple orange pear banana}}); select {{word}} in ${{{fruits[@]}}}; do echo ${{word}}; doneContext
tldr-pages: common/select
Revisions (0)
No revisions yet.