[raspberry-vi] Re: scripts

  • From: Michael A Ray <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "mike.ray" for DMARC)
  • To: raspberry-vi@xxxxxxxxxxxxx
  • Date: Fri, 15 Jan 2021 21:59:08 +0000



The top line of a bash script, or other interpreted file, is called the
'shebang'. And it tells the OS what interpreter to use for the script.

Typically in a bash script it would be:

#!/bin/bash

But it might be different if your OS puts it somewhere else.

I suspect Arch puts bash in /usr/bin, but there is probably a link in
/bin/bash.

Python typically uses:

#!/usr/bin/env python

Which does not specify the Python version, but leaves it up to the env
to find which one. Here 'python' is an argument to the env exec.

Perl used to be:

#!/usr/bin/perl -w

But the -w is out of fashion now, since:

use warnings

In the script does the job.

Some other examples could be:

#!/usr/bin/node

For nodejs.

And:

#!/usr/bin/tcl

For tickle.

In scripts designed for production use, it is quite common to see any
file extension left off completely.

A script called, for example, sync-to-backup, written in bash and
bearing the correct shebang works just as well with no extension.

To make a script executable, I prefer:

chmod +x scriptname.sh

Because I'm too lazy to take the extra three seconds to think of the
bitmask.








On 15/01/2021 19:34, Mewtamer wrote:

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



-- 
Michael A. Ray
Analyst/Programmer
Witley, Surrey, South-east UK

"Perfection is achieved, not when there is nothing more to add, but when
there is nothing left to take away." -- A. de Saint-Exupery

https://cromarty.github.io/
http://eyesfreelinux.ninja/
http://www.raspberryvi.org/


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