[raspberry-vi] Re: scripts

  • From: Dan Miner <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "dminer84" for DMARC)
  • To: <raspberry-vi@xxxxxxxxxxxxx>
  • Date: Fri, 15 Jan 2021 14:59:40 -0700

I've done tons of bash scripting and it is fairly straight forward but one of 
your first surprises will probably be trying to run a script from the Desktop 
of your GUI and nothing "appears" to happen.  Unlike Windows, there is no 
default graphical terminal associated with scripts.  Thus they  just run, find 
no standard input or output and end or fail badly.  So, I recommend for 
starters to stick to running text based scripts in a terminal you have already 
opened.  Thus I do this for every new account I create:

mkdir ~/bin

You'll likely have to restart your GUI session for the system to automatically 
add that bin directory to your login session.

Now you have a nice home for scripts to live and be on your personal PATH for 
other scripts and terminals to find.  The next piece of detail is that command 
line arguments given to your script when they run can be accessed via $1, $2, 
.., "$@".  The "$@" is how to access them as a whole for arrays and pass along 
to other programs.  There are many bash tutorials out there from poor to great, 
so enjoy learning the true power of the "command line".  *smile*

        Dan


-----Original Message-----
From: raspberry-vi-bounce@xxxxxxxxxxxxx <raspberry-vi-bounce@xxxxxxxxxxxxx> On 
Behalf Of Glenn K0LNY
Sent: Friday, January 15, 2021 12:46 PM
To: raspberry-vi@xxxxxxxxxxxxx
Subject: [raspberry-vi] Re: scripts

Thanks Mewtamer and Dan,
It would be nice to make one script for all the lines so maybe I could run it 
and go through the presets.
Glenn

----- Original Message -----
From: "Mewtamer" <mewtamer@xxxxxxxxx>
To: <raspberry-vi@xxxxxxxxxxxxx>
Sent: Friday, January 15, 2021 1:34 PM
Subject: [raspberry-vi] Re: scripts


a few things to note:

1. Filename extensions aren't really used by Linux for identifying
file types and deciding what to do with them when opened in a
graphical file manager, but convention is to name shell scripts with a
.sh extension.

2. Generally, you want to start a script with the line:

#! /bin/bash

To designate how the script should be parsed. Technically, this is
specifically for bash scripts, but I think it's generally assumed your
doing bash if your aren't specifying a language such as perl or
python(in which cas the #! line will include the path to the
perl/python commands). You can omit this line, but then you have to
run bash script.sh everytime you want to run it.

3. You'll need to make the file executable. The easiest way I know to
do this is to run

chmod 755 *.sh

in the folder with all your scripts. Note: 755 means grant owner red,
write, execute, group read execute, and others read execute
privileges. More generally, read is 4, write is 2, and execute is 1,
the first digit is owner, the second is group, and the third is others
and you simply sum up the values of the privileges you want to grant.
Also, I'm pretty sure you'll need to do this after the copy as I don't
think Windows comprehends Unix-style file permissions and I don't
think they are supported on FAT filesystems.

4. Different OSes use different line endings for text files. Most
modern text editors can handle this without problem, but if your using
Notepad and it saves the scripts with DOS-style line breaks, I'm not
sure if that'll cause issues running the script after copying it over.

5. All that said, if the script is just the #! line and a single line
containing what you would type at the command line to invoke the radio
software manually, I can think of no reason it wouldn't work.

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.
===========================================================
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: