SlideShare a Scribd company logo
#!/bin/echo Source this file: .
#@ Name: menu
#@ Version: 1.0
#@ Description:
#@ Author: Chris F.A. Johnson
#@ Usage:
#@ Created: 2013-01-18
#@ Modified: 2013-01-20 18:43:39
menu() #@ Allow multiple selections from array (menu title in array[0])
{ #@ USAGE: menu arrayname #: selections stored in ${selections[@]}
local arrayname=${1:?Array name required} title varname bar c n w
bar=======================================================================
## Copy the array, $arrayname, to local array
eval "array=( "${$arrayname[@]}" )"
title=${array[0]}
array[0]=Exit
w=${#array[@]}
w=${#w}
bar=${bar:0:${#title}+6}
printf "%sn" "$bar"
printf " %sn" "$title"
printf "%sn" "$bar"
for n in "${!array[@]}"
do
printf " %${w}d: %sn" "$n" "${array[n]}"
done
printf "%sn" "$bar" ''
while :
do
read -p $'Add to selection:e[K ' choice
case $choice in
""| 0) break ;;
*[!0-9]*) ;;
*) [ $choice -gt 0 ] && [ $choice -le "${#array[@]}" ] &&
selections+=( "${array[choice]}" ) ;;
esac
printf 'e[2Ae[K'
printf "%s " "${selections[@]}"
echo
done
}

More Related Content

PDF
PHP 101
PDF
Formidable ES6 spread operator in JavaScript
PDF
My First Ruby
PPT
Class 4 - PHP Arrays
ODP
Functional perl
PDF
Simplifying code monster to elegant in n 5 steps
PPTX
Data structure in perl
PDF
Quick reference for Grafana
PHP 101
Formidable ES6 spread operator in JavaScript
My First Ruby
Class 4 - PHP Arrays
Functional perl
Simplifying code monster to elegant in n 5 steps
Data structure in perl
Quick reference for Grafana

What's hot (18)

PDF
WordCamp Portland 2018: PHP for WordPress
PDF
Taking Perl to Eleven with Higher-Order Functions
PPTX
Python Collection datatypes
DOCX
Procedure To Store Database Object Size And Number Of Rows In Custom Table
KEY
Desarrollando aplicaciones web en minutos
PPTX
Array,lists and hashes in perl
PPT
Php array
PDF
Php array
PPT
PDF
20190330 immutable data
TXT
My shell
PPT
Php Using Arrays
PDF
Systemtabledetailsquery
PDF
Road to Power Query NINJA – 1st STEP
PDF
Perl6 one-liners
PDF
{shiny}と{leaflet}による地図アプリ開発Tips
PDF
8時間耐久CakePHP2 勉強会
WordCamp Portland 2018: PHP for WordPress
Taking Perl to Eleven with Higher-Order Functions
Python Collection datatypes
Procedure To Store Database Object Size And Number Of Rows In Custom Table
Desarrollando aplicaciones web en minutos
Array,lists and hashes in perl
Php array
Php array
20190330 immutable data
My shell
Php Using Arrays
Systemtabledetailsquery
Road to Power Query NINJA – 1st STEP
Perl6 one-liners
{shiny}と{leaflet}による地図アプリ開発Tips
8時間耐久CakePHP2 勉強会
Ad

Viewers also liked (15)

PDF
Coursera Machine Learning
TXT
Cpsh sh
TXT
Menu func-sh
TXT
Pop3stat sh
TXT
Phdel sh
TXT
Popstat1 sh
TXT
Luhn sh
TXT
Phadd sh
PDF
Programming collaborative-ref
TXT
An a z index of windows power shell commandss
TXT
Compound var
TXT
An a z index of the bash commands
TXT
Xz file-format-1.0.4
TXT
Applecmdlista zs
TXT
Getfilestruct zbksh(1)
Coursera Machine Learning
Cpsh sh
Menu func-sh
Pop3stat sh
Phdel sh
Popstat1 sh
Luhn sh
Phadd sh
Programming collaborative-ref
An a z index of windows power shell commandss
Compound var
An a z index of the bash commands
Xz file-format-1.0.4
Applecmdlista zs
Getfilestruct zbksh(1)
Ad

Recently uploaded (20)

PPT
ASRH Presentation for students and teachers 2770633.ppt
PPTX
Important Obstetric Emergency that must be recognised
PPTX
Electrolyte Disturbance in Paediatric - Nitthi.pptx
PPTX
obstructive neonatal jaundice.pptx yes it is
PDF
Handout_ NURS 220 Topic 10-Abnormal Pregnancy.pdf
PPT
OPIOID ANALGESICS AND THEIR IMPLICATIONS
PPTX
antibiotics rational use of antibiotics.pptx
PPT
Obstructive sleep apnea in orthodontics treatment
PPTX
History and examination of abdomen, & pelvis .pptx
PDF
Cardiology Pearls for Primary Care Providers
PPTX
NASO ALVEOLAR MOULDNIG IN CLEFT LIP AND PALATE PATIENT
PPTX
Stimulation Protocols for IUI | Dr. Laxmi Shrikhande
PPTX
Acid Base Disorders educational power point.pptx
PPTX
regulatory aspects for Bulk manufacturing
PPT
MENTAL HEALTH - NOTES.ppt for nursing students
PDF
Oral Aspect of Metabolic Disease_20250717_192438_0000.pdf
PPTX
Neuropathic pain.ppt treatment managment
PPTX
surgery guide for USMLE step 2-part 1.pptx
PPT
Management of Acute Kidney Injury at LAUTECH
PDF
Copy of OB - Exam #2 Study Guide. pdf
ASRH Presentation for students and teachers 2770633.ppt
Important Obstetric Emergency that must be recognised
Electrolyte Disturbance in Paediatric - Nitthi.pptx
obstructive neonatal jaundice.pptx yes it is
Handout_ NURS 220 Topic 10-Abnormal Pregnancy.pdf
OPIOID ANALGESICS AND THEIR IMPLICATIONS
antibiotics rational use of antibiotics.pptx
Obstructive sleep apnea in orthodontics treatment
History and examination of abdomen, & pelvis .pptx
Cardiology Pearls for Primary Care Providers
NASO ALVEOLAR MOULDNIG IN CLEFT LIP AND PALATE PATIENT
Stimulation Protocols for IUI | Dr. Laxmi Shrikhande
Acid Base Disorders educational power point.pptx
regulatory aspects for Bulk manufacturing
MENTAL HEALTH - NOTES.ppt for nursing students
Oral Aspect of Metabolic Disease_20250717_192438_0000.pdf
Neuropathic pain.ppt treatment managment
surgery guide for USMLE step 2-part 1.pptx
Management of Acute Kidney Injury at LAUTECH
Copy of OB - Exam #2 Study Guide. pdf

Menu func-sh(1)

  • 1. #!/bin/echo Source this file: . #@ Name: menu #@ Version: 1.0 #@ Description: #@ Author: Chris F.A. Johnson #@ Usage: #@ Created: 2013-01-18 #@ Modified: 2013-01-20 18:43:39 menu() #@ Allow multiple selections from array (menu title in array[0]) { #@ USAGE: menu arrayname #: selections stored in ${selections[@]} local arrayname=${1:?Array name required} title varname bar c n w bar======================================================================= ## Copy the array, $arrayname, to local array eval "array=( "${$arrayname[@]}" )" title=${array[0]} array[0]=Exit w=${#array[@]} w=${#w} bar=${bar:0:${#title}+6} printf "%sn" "$bar" printf " %sn" "$title" printf "%sn" "$bar" for n in "${!array[@]}" do printf " %${w}d: %sn" "$n" "${array[n]}" done printf "%sn" "$bar" '' while : do read -p $'Add to selection:e[K ' choice case $choice in ""| 0) break ;; *[!0-9]*) ;; *) [ $choice -gt 0 ] && [ $choice -le "${#array[@]}" ] && selections+=( "${array[choice]}" ) ;; esac printf 'e[2Ae[K' printf "%s " "${selections[@]}" echo done }