howid.
i have been looking something for either bash or python or mac terminal menu
i want it to look like this ,,,
1 : firefox
2: bean.
3 skype
4 exit.
you get my drift.
why, because i want to.
found many examples online but many are full of errors and i dont trust them
i have given up for now.
AuntyGravity
(289 posts)Here's a list!
https://www.unite.ai/best-ai-code-generators/
I'd be interested in your results if you decide to experiment with this interesting tech.
Useful or hooey?
usonian
(13,782 posts)I copied the bash script from this site:
https://askubuntu.com/questions/1705/how-can-i-create-a-select-menu-in-a-shell-script
I INSERTED SPACES TO KEEP DU FROM DISPLAYING SMILIES!!!
NEVER PUT A CLOSE PAREN AFTER A DOUBLE QUOTE.
YOU GET THIS "
And DU doesn't honor indents. It's not a code site.
Question:
I'm creating a simple bash script and I want to create a select menu in it, like this:
$./script
echo "Choose your option:"
1) Option 1
2) Option 2
3) Option 3
4) Quit
Answer 1
#!/bin/bash
# Bash Menu Script Example
PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit" )
select opt in "${options[@]}"
do
case $opt in
"Option 1" )
echo "you chose choice 1"
;;
"Option 2" )
echo "you chose choice 2"
;;
"Option 3" )
echo "you chose choice $REPLY which is $opt"
;;
"Quit" )
break
;;
*) echo "invalid option $REPLY";;
esac
done
Looks easy enough.
Mac version (tested and works)
#!/bin/bash
# Bash Menu Script Example
PS3='Please enter your choice: '
options=("Clock" "Notes" "Stickies" "Quit" )
select opt in "${options[@]}"
do
case $opt in
"Clock" )
open -a Clock &
;;
"Notes" )
open -a Notes &
;;
"Stickies" )
open -a Stickies &
;;
"Quit" )
break
;;
*) echo "invalid option $REPLY";;
esac
done
It works with the space between the " and the )
And prints on DU
One could get fancier. I didn't even read the other answers.
Bash is essential to computer use!
You BASH the computer or the computer BASHES you.
For anything more deluxe, use Tcl and Tk.
They are interpreted and have a GUI toolkit (Tk)
Active State has an installer. Free
https://www.activestate.com/products/tcl/
Note on the above.
I put that code into a script, called it do
chmod +x do
./do
Anyway, here's a screenshot FYI to show the indentation (for looks in Bash. Indentation counts in Python)
AllaN01Bear
(23,039 posts)AllaN01Bear
(23,039 posts)AllaN01Bear
(23,039 posts)information and timely research. will play with it more when i get home from church. now off to bed .
usonian
(13,782 posts)Just had to brush up. It has been a long while.
On a mac, applescript is probably best. (Automator is applescript with a GUI and recorder)
On the mac, the terminal loses focus, so you have to click on its window to re-activate it.
Good luck.
AllaN01Bear
(23,039 posts)usonian
(13,782 posts)It doesn't really go into detail.
Perhaps the O'Reilly free book I linked might be better. Haven't read it in a while.
https://github.com/jlevy/the-art-of-command-line?tab=readme-ov-file#meta