Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Should script files have a .sh suffix?

16 views
Skip to first unread message

Charlie Gibbs

unread,
Sep 7, 2023, 5:24:46 PM9/7/23
to
We have a system consisting of dozens of executables and a number of
scripts, some of which are run automatically. In the Windows version,
the executables have a .exe suffix and scripts (a.k.a. batch files)
have a .bat suffix. So far I've written the Linux version so that
neither executables nor scripts have a suffix. However, our support
people want to be able to easily grab copies of all scripts (e.g. for
backups). If I were to modify the system so that all scripts have a
.sh suffix, that would satisfy this wish.

I've searched the web in various places (including stackoverflow)
and found lots of conflicting information over whether a .sh suffix
is desirable. So I thought I'd throw out the question here.

Just when you thought the Ford vs. Chevy debate had died down...

--
/~\ Charlie Gibbs | They offer a huge range of
\ / <cgi...@kltpzyxm.invalid> | world-class vulnerabilities
X I'm really at ac.dekanfrus | that only Microsoft can provide.
/ \ if you read it the right way. | -- druck <ne...@druck.org.uk>

Richard Kettlewell

unread,
Sep 7, 2023, 5:29:53 PM9/7/23
to
Charlie Gibbs <cgi...@kltpzyxm.invalid> writes:
> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files)
> have a .bat suffix. So far I've written the Linux version so that
> neither executables nor scripts have a suffix. However, our support
> people want to be able to easily grab copies of all scripts (e.g. for
> backups). If I were to modify the system so that all scripts have a
> .sh suffix, that would satisfy this wish.
>
> I've searched the web in various places (including stackoverflow)
> and found lots of conflicting information over whether a .sh suffix
> is desirable. So I thought I'd throw out the question here.

The OS doesn’t care. Do whatever’s most convenient for the humans who
will actually be using the system.

--
https://www.greenend.org.uk/rjk/

Computer Nerd Kev

unread,
Sep 7, 2023, 6:42:09 PM9/7/23
to
Charlie Gibbs <cgi...@kltpzyxm.invalid> wrote:
> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files)
> have a .bat suffix. So far I've written the Linux version so that
> neither executables nor scripts have a suffix. However, our support
> people want to be able to easily grab copies of all scripts (e.g. for
> backups). If I were to modify the system so that all scripts have a
> .sh suffix, that would satisfy this wish.
>
> I've searched the web in various places (including stackoverflow)
> and found lots of conflicting information over whether a .sh suffix
> is desirable. So I thought I'd throw out the question here.

I've seen arguments against it, but my preference is to use .sh for
easier identification, however if a script is run from the
command-line I prefer to make a symlink to it without the .sh
extension. That avoids adding length to commands, and also solves
the problem of what to do if you want to rewrite it in another
language later but lots of scripts/people call it by the existing
name.

File managers also know what to open a .sh file with, short of
running something like "file" over everything (which I guess some
probably do).

--
__ __
#_ < |\| |< _#

Robert Heller

unread,
Sep 7, 2023, 6:57:16 PM9/7/23
to
Although Linux and UNIX binary executables (eg "a.out" files), generally have
no extension, I have used packages where such files are given an extension as
a convension.

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

John McCue

unread,
Sep 7, 2023, 7:31:20 PM9/7/23
to
Charlie Gibbs <cgi...@kltpzyxm.invalid> wrote:
> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files)
> have a .bat suffix. So far I've written the Linux version so that
> neither executables nor scripts have a suffix. However, our support
> people want to be able to easily grab copies of all scripts (e.g. for
> backups). If I were to modify the system so that all scripts have a
> .sh suffix, that would satisfy this wish.

If this is a production system, I would say *no*. Some
objects may fail. You should teach them to use file(1).

If you must do something, I would symbolic the scripts to
whatever.sh to make them happy :)


<snip>
--
[t]csh(1) - "An elegant shell, for a more... civilized age."
- Paraphrasing Star Wars

David W. Hodgins

unread,
Sep 7, 2023, 8:25:23 PM9/7/23
to
On Thu, 07 Sep 2023 18:41:57 -0400, Computer Nerd Kev <n...@telling.you.invalid> wrote:
> File managers also know what to open a .sh file with, short of
> running something like "file" over everything (which I guess some
> probably do).

A file manager should not be choosing how to execute a script, and I don't know
of any that do.

How anything gets executed in linux is controlled by the kernel when execv is
called. If it starts with .ELF then it's a binary elf executable, if it starts
with #! then it's a script, that is to be interpreted by the executable that
is in the text after #!. If it's a text file without a shebang then it uses
the interpreter listed for that user in /etc/passwd.

There are places where the extension does matter. In the case of the script
/etc/profile, the executable files in /etc/profile.d/*.sh are executed when
logging in using bash. Those that end in .csh are executed when logging in with
csh, etc.

For scripts that the user runs though, the extension does not matter to the system
though it may or may not matter to the user.

Regards, Dave Hodgins

Computer Nerd Kev

unread,
Sep 7, 2023, 9:54:40 PM9/7/23
to
David W. Hodgins <dwho...@nomail.afraid.org> wrote:
> On Thu, 07 Sep 2023 18:41:57 -0400, Computer Nerd Kev <n...@telling.you.invalid> wrote:
>> File managers also know what to open a .sh file with, short of
>> running something like "file" over everything (which I guess some
>> probably do).
>
> A file manager should not be choosing how to execute a script, and I don't know
> of any that do.

By "open" I meant "view/edit". I wouldn't run/execute a script file
from a file manager interface out of preference. If a file manager
called that "opening", I'd be immediately confused.

David W. Hodgins

unread,
Sep 7, 2023, 11:21:14 PM9/7/23
to
On Thu, 07 Sep 2023 21:54:22 -0400, Computer Nerd Kev <n...@telling.you.invalid> wrote:
> By "open" I meant "view/edit". I wouldn't run/execute a script file
> from a file manager interface out of preference. If a file manager
> called that "opening", I'd be immediately confused.

Ok. Gotcha. Some file managers allow viewing, editing, or executing files.

Regards, Dave Hodgins

Marco Moock

unread,
Sep 8, 2023, 2:48:27 AM9/8/23
to
Am 07.09.2023 schrieb Charlie Gibbs <cgi...@kltpzyxm.invalid>:

> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files)
> have a .bat suffix. So far I've written the Linux version so that
> neither executables nor scripts have a suffix. However, our support
> people want to be able to easily grab copies of all scripts (e.g. for
> backups). If I were to modify the system so that all scripts have a
> .sh suffix, that would satisfy this wish.

The file system itself doesn't care and bash also doesn't care.
Relevant in shell scrips is the interpreter, the line that starts with
#. The script also needs to be executable to directly run it. If not,
you have to run "bash script(.sh)".

I recommend using the file extensions because it makes it easy to
identify the content without opening.

Giovanni

unread,
Sep 8, 2023, 2:58:01 AM9/8/23
to
On 9/7/23 23:24, Charlie Gibbs wrote:
> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files)
> have a .bat suffix. So far I've written the Linux version so that
> neither executables nor scripts have a suffix. However, our support
> people want to be able to easily grab copies of all scripts (e.g. for
> backups). If I were to modify the system so that all scripts have a
> .sh suffix, that would satisfy this wish.

In the Linux/Unix world no suffix is required but executables are
identified from their file mode being executable. Windows has no such
file mode and uses the extension to detect a file as executable.

Ciao
Giovanni
--
A computer is like an air conditioner,
it stops working when you open Windows.
< https://giovanni.homelinux.net/ >

The Natural Philosopher

unread,
Sep 8, 2023, 3:09:06 AM9/8/23
to
On 07/09/2023 22:24, Charlie Gibbs wrote:
> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files)
> have a .bat suffix. So far I've written the Linux version so that
> neither executables nor scripts have a suffix. However, our support
> people want to be able to easily grab copies of all scripts (e.g. for
> backups). If I were to modify the system so that all scripts have a
> .sh suffix, that would satisfy this wish.
>
> I've searched the web in various places (including stackoverflow)
> and found lots of conflicting information over whether a .sh suffix
> is desirable. So I thought I'd throw out the question here.
>
> Just when you thought the Ford vs. Chevy debate had died down...
>
I myself pop a .sh on the back simply to identify them as things I have
written. They also have their own directory. /usr/local/scripts.

But as with all things *nix, nothing is mandatory. Their name is
entirely down to what standards and conventions you choose to set.


--
“it should be clear by now to everyone that activist environmentalism
(or environmental activism) is becoming a general ideology about humans,
about their freedom, about the relationship between the individual and
the state, and about the manipulation of people under the guise of a
'noble' idea. It is not an honest pursuit of 'sustainable development,'
a matter of elementary environmental protection, or a search for
rational mechanisms designed to achieve a healthy environment. Yet
things do occur that make you shake your head and remind yourself that
you live neither in Joseph Stalin’s Communist era, nor in the Orwellian
utopia of 1984.”

Vaclav Klaus

Blue-Maned_Hawk

unread,
Sep 8, 2023, 6:19:33 AM9/8/23
to
On Thu, 07 Sep 2023 21:24:40 GMT, Charlie Gibbs wrote:

> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files) have
> a .bat suffix. So far I've written the Linux version so that neither
> executables nor scripts have a suffix. However, our support people want
> to be able to easily grab copies of all scripts (e.g. for backups). If
> I were to modify the system so that all scripts have a .sh suffix, that
> would satisfy this wish.
>
> I've searched the web in various places (including stackoverflow)
> and found lots of conflicting information over whether a .sh suffix is
> desirable. So I thought I'd throw out the question here.
>
> Just when you thought the Ford vs. Chevy debate had died down...

It seems to me like your support people could just get the files based on
whether or not they have a shebang line or not—suffixing the files
with .sh would be redundant for identification.



--
Blue-Maned_Hawk│shortens to Hawk│/blu.mɛin.dʰak/│he/him/
his/himself/Mr. bluemanedhawk.github.io
The fact that 'shelled' means 'shell has been removed' and not 'shell has
been left on' is not intuitive.

Woozy Song

unread,
Sep 8, 2023, 7:01:34 AM9/8/23
to
Charlie Gibbs wrote:
> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files)
> have a .bat suffix. So far I've written the Linux version so that
> neither executables nor scripts have a suffix. However, our support
> people want to be able to easily grab copies of all scripts (e.g. for
> backups). If I were to modify the system so that all scripts have a
> .sh suffix, that would satisfy this wish.
>
> I've searched the web in various places (including stackoverflow)
> and found lots of conflicting information over whether a .sh suffix
> is desirable. So I thought I'd throw out the question here.
>
> Just when you thought the Ford vs. Chevy debate had died down...
>

I use an "agnostic" package written long ago. It has .sh scripts for
bash and .csh scripts for csh.

Carlos E. R.

unread,
Sep 8, 2023, 9:56:50 AM9/8/23
to
On 2023-09-07 17:24, Charlie Gibbs wrote:
> We have a system consisting of dozens of executables and a number of
> scripts, some of which are run automatically. In the Windows version,
> the executables have a .exe suffix and scripts (a.k.a. batch files)
> have a .bat suffix. So far I've written the Linux version so that
> neither executables nor scripts have a suffix. However, our support
> people want to be able to easily grab copies of all scripts (e.g. for
> backups). If I were to modify the system so that all scripts have a
> .sh suffix, that would satisfy this wish.
>
> I've searched the web in various places (including stackoverflow)
> and found lots of conflicting information over whether a .sh suffix
> is desirable. So I thought I'd throw out the question here.
>
> Just when you thought the Ford vs. Chevy debate had died down...

The system does not care, the humans do.

However, changes on a system "in production" can be disruptive. You may
cause other tools that already know the name of a script to fail. Or you
may decide at some point to recreate a script as a binary and have to
rename the extension.

Also, the backup may miss scripts that don't have the extension
(forgotten), so I'd say that your support system should make the backup
based on other criteria, like examining the start of a file to find out
what type it actually is.

--
Cheers,
Carlos E.R.

David W. Hodgins

unread,
Sep 8, 2023, 11:44:25 AM9/8/23
to
On Fri, 08 Sep 2023 02:57:54 -0400, Giovanni <lso...@home.net.it> wrote:

> On 9/7/23 23:24, Charlie Gibbs wrote:
>> We have a system consisting of dozens of executables and a number of
>> scripts, some of which are run automatically. In the Windows version,
>> the executables have a .exe suffix and scripts (a.k.a. batch files)
>> have a .bat suffix. So far I've written the Linux version so that
>> neither executables nor scripts have a suffix. However, our support
>> people want to be able to easily grab copies of all scripts (e.g. for
>> backups). If I were to modify the system so that all scripts have a
>> .sh suffix, that would satisfy this wish.
>
> In the Linux/Unix world no suffix is required but executables are
> identified from their file mode being executable. Windows has no such
> file mode and uses the extension to detect a file as executable.

In linux, the extension is not required for the kernel to be able to run
a script. It is required in by some tools such as /etc/profile.

It's required by udev which only loads rules if the file name they are stored
in ends with ".rule". Under systemd there are various extensions used,
.service, .target, .wants, etc. They must be correct or they will not be
processed. There are many other tools that also select files based on the
extension.

So saying "the extension is not required" is true for a script or other
executable run directly by the linux kernel, but not true for things
including scripts selected by various tools.

Regards, Dave Hodgins

Charlie Gibbs

unread,
Sep 8, 2023, 2:04:09 PM9/8/23
to
Thanks for all the opinions. I'm leaning toward adding the .sh suffix
to existing scripts. There aren't that many, and I could even modify
the one that runs every night to update existing ones as required.

Most of our people were born and raised on Windows, and it'll take a
bit of work to wean them off Microsoft's worship of file extensions.
I could shoot their sacred cow with something like

cp -p $(file * | grep script | cut -d: -f1) $BACKUPDIR

although it would be more palatable if they could just say

cp -p *.sh $BACKUPDIR

David W. Hodgins

unread,
Sep 8, 2023, 6:24:22 PM9/8/23
to
On Fri, 08 Sep 2023 14:04:03 -0400, Charlie Gibbs <cgi...@kltpzyxm.invalid> wrote:
> Most of our people were born and raised on Windows, and it'll take a
> bit of work to wean them off Microsoft's worship of file extensions.
> I could shoot their sacred cow with something like
>
> cp -p $(file * | grep script | cut -d: -f1) $BACKUPDIR
>
> although it would be more palatable if they could just say
>
> cp -p *.sh $BACKUPDIR

The file command is very quick, and just backing up .sh files may miss some
that you would want.

$ time file /etc/profile.d/* |grep exec
/etc/profile.d/10tmpdir.sh: POSIX shell script, ASCII text executable
/etc/profile.d/40configure_keyboard.sh: POSIX shell script, ASCII text executable
/etc/profile.d/60alias.sh: POSIX shell script, ASCII text executable
/etc/profile.d/60qt5.csh: C shell script, ASCII text executable
/etc/profile.d/60qt5.sh: Bourne-Again shell script, ASCII text executable
/etc/profile.d/65qt4.sh: Bourne-Again shell script, ASCII text executable
/etc/profile.d/90qtdir3.sh: Bourne-Again shell script, ASCII text executable
/etc/profile.d/ladspa.csh: C shell script, ASCII text executable
/etc/profile.d/ladspa.sh: POSIX shell script, ASCII text executable
/etc/profile.d/zlocal.sh: POSIX shell script, ASCII text executable

real 0m0.154s
user 0m0.155s
sys 0m0.001s

I'd use file "$BACKUPDIR"/*|grep exec. Note the use of double quotes as windows
users are more likely to use spaces in file and directory names, and then parse
that list for the names of the files to backup.

Regards, Dave Hodgins
0 new messages