[raspberry-vi] Re: scripts

  • From: Travis Siegel <tsiegel@xxxxxxxxxxx>
  • To: raspberry-vi@xxxxxxxxxxxxx, Glenn K0LNY <glennervin@xxxxxxxxxxxx>
  • Date: Fri, 15 Jan 2021 23:02:48 -0500

Yep, sure can.

Every command you enter between the option and the two semi-colons will 
be executed when that option is selected.

and

On 1/15/2021 10:55 PM, Glenn K0LNY wrote:

This is pretty cool, and here's another question, if I run this after
silencing Orca, can I put in a line that would do something like:
espeak "playing weather radio"

Thanks
----- Original Message -----
From: "Travis Siegel" <tsiegel@xxxxxxxxxxx>
To: <raspberry-vi@xxxxxxxxxxxxx>; "Mewtamer" <mewtamer@xxxxxxxxx>
Sent: Friday, January 15, 2021 9:33 PM
Subject: [raspberry-vi] Re: scripts



On 1/15/2021 2:34 PM, Mewtamer wrote:
6. It's an advanced scripting technique I'm not familiar with myself,
but I'm pretty sure you can do menus in bash scripts, so if each
script is just one line invoking the radio program for a specific
station, it should be possible to combine them into a single script
that acts as a menu of presets for the radio program.


Yep, you sure can, and it's relatively simple, it's basically just a
case statement with the commands you want executed after selecting an
option.

This example (I snagged from online and reformatted to show how simple
it is), will do the trick nicely.

Do note that you can run more than one command in each select statement,
so if you have start/shutdown commands, they can be added to each case
as well, and they will also be executed along with any command you add
to actually change to the selected frequency.

$reply contains the text typed in by the user, and $opt contains the
text printed for that particular menu option.

I can never remember if formatting is important in bash scripts, since I
rarely (if ever) use indentation for bash scripts. I'm fairly certain
spacing isn't necessary, but

** cut here**


echo 'Please enter your choice: '
options=(
"162.500"
"163.800"
"175.425"
"Quit"
)
select opt in "${options[@]}"
do
case $opt in
"162.500")
echo "Playing weather radio."

play 162.500

;;

   "163.800")

echo "Playing baseball game"

play baseball

;;
"175.425")
echo "Playing $REPLY."

play $opt

;;
   "Quit")
   break
   ;;
   *) echo "invalid option $REPLY";;
   esac
done

** cut here **


Hope this helps.


===========================================================
The raspberry-vi mailing list
Archives: //www.freelists.org/archives/raspberry-vi
Administrative contact: <mike.ray@xxxxxxxxxxxxxx>
-----------------------------------------------------------
Raspberry Pi and the Raspberry Pi logo are trademarks of the Raspberry Pi
Foundation.

This list is not affiliated to the Raspberry Pi Foundation and the views and
attitudes expressed by the subscribers to this list do not reflect those of
the Foundation.

Mike Ray, list creator, January 2013

===========================================================
The raspberry-vi mailing list
Archives: //www.freelists.org/archives/raspberry-vi
Administrative contact: <mike.ray@xxxxxxxxxxxxxx>
-----------------------------------------------------------
Raspberry Pi and the Raspberry Pi logo are trademarks of the Raspberry Pi 
Foundation.

This list is not affiliated to the Raspberry Pi Foundation and the views and 
attitudes expressed by the subscribers to this list do not reflect those of 
the Foundation.

Mike Ray, list creator, January 2013

=========================================================== 
The raspberry-vi mailing list 
Archives: //www.freelists.org/archives/raspberry-vi
Administrative contact: <mike.ray@xxxxxxxxxxxxxx>
-----------------------------------------------------------
Raspberry Pi and the Raspberry Pi logo are trademarks of the Raspberry Pi 
Foundation.

This list is not affiliated to the Raspberry Pi Foundation and the views and 
attitudes expressed by the subscribers to this list do not reflect those of the 
Foundation.

Mike Ray, list creator, January 2013

Other related posts: