• Should script files have a .sh suffix?

    From Charlie Gibbs@21:1/5 to All on Thu Sep 7 21:24:40 2023
    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
    \ / <cgibbs@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 <news@druck.org.uk>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Charlie Gibbs on Thu Sep 7 22:29:48 2023
    Charlie Gibbs <cgibbs@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/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Computer Nerd Kev@21:1/5 to Charlie Gibbs on Fri Sep 8 08:41:57 2023
    Charlie Gibbs <cgibbs@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).

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to invalid@invalid.invalid on Thu Sep 7 22:57:06 2023
    At Thu, 07 Sep 2023 22:29:48 +0100 Richard Kettlewell <invalid@invalid.invalid> wrote:


    Charlie Gibbs <cgibbs@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.


    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
    heller@deepsoft.com -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John McCue@21:1/5 to Charlie Gibbs on Thu Sep 7 23:31:15 2023
    Charlie Gibbs <cgibbs@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David W. Hodgins@21:1/5 to Computer Nerd Kev on Thu Sep 7 20:25:12 2023
    On Thu, 07 Sep 2023 18:41:57 -0400, Computer Nerd Kev <not@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Computer Nerd Kev@21:1/5 to David W. Hodgins on Fri Sep 8 11:54:22 2023
    David W. Hodgins <dwhodgins@nomail.afraid.org> wrote:
    On Thu, 07 Sep 2023 18:41:57 -0400, Computer Nerd Kev <not@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.

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David W. Hodgins@21:1/5 to Computer Nerd Kev on Thu Sep 7 23:15:12 2023
    On Thu, 07 Sep 2023 21:54:22 -0400, Computer Nerd Kev <not@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marco Moock@21:1/5 to All on Fri Sep 8 08:48:21 2023
    Am 07.09.2023 schrieb Charlie Gibbs <cgibbs@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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Giovanni@21:1/5 to Charlie Gibbs on Fri Sep 8 08:57:54 2023
    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/ >

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From The Natural Philosopher@21:1/5 to Charlie Gibbs on Fri Sep 8 08:09:00 2023
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Woozy Song@21:1/5 to Charlie Gibbs on Fri Sep 8 19:01:27 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Blue-Maned_Hawk@21:1/5 to Charlie Gibbs on Fri Sep 8 10:19:27 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Carlos E. R.@21:1/5 to Charlie Gibbs on Fri Sep 8 09:56:43 2023
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David W. Hodgins@21:1/5 to Giovanni on Fri Sep 8 11:43:05 2023
    On Fri, 08 Sep 2023 02:57:54 -0400, Giovanni <lsodgf0@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to Carlos E. R. on Fri Sep 8 18:04:03 2023
    On 2023-09-08, Carlos E. R. <robin_listas@es.invalid> wrote:

    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.

    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

    --
    /~\ Charlie Gibbs | They offer a huge range of
    \ / <cgibbs@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 <news@druck.org.uk>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David W. Hodgins@21:1/5 to Charlie Gibbs on Fri Sep 8 15:43:41 2023
    On Fri, 08 Sep 2023 14:04:03 -0400, Charlie Gibbs <cgibbs@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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)