What do you advice for shell usage?

  • Do you use bash? If not, which one do you use? zsh, fish? Why do you do it?
  • Do you write #!/bin/bash or #!/bin/sh? Do you write fish exclusive scripts?
  • Do you have two folders, one for proven commands and one for experimental?
  • Do you publish/ share those commands?
  • Do you sync the folder between your server and your workstation?
  • What should’ve people told you what to do/ use?
  • good practice?
  • general advice?
  • is it bad practice to create a handful of commands like podup and poddown that replace podman compose up -d and podman compose down or podlog as podman logs -f --tail 20 $1 or podenter for podman exec -it "$1" /bin/sh?

Background

I started bookmarking every somewhat useful website. Whenever I search for something for a second time, it’ll popup as the first search result. I often search for the same linux commands as well. When I moved to atomic Fedora, I had to search for rpm-ostree (POV: it was a horrible command for me, as a new user, to remember) or sudo ostree admin pin 0. Usually, I bookmark the website and can get back to it. One day, I started putting everything into a .bashrc file. Sooner rather than later I discovered that I could simply add ~/bin to my $PATH variable and put many useful scripts or commands into it.

For the most part I simply used bash. I knew that you could somehow extend it but I never did. Recently, I switched to fish because it has tab completion. It is awesome and I should’ve had completion years ago. This is a game changer for me.

I hated that bash would write the whole path and I was annoyed by it. I added PS1="$ " to my ~/.bashrc file. When I need to know the path, I simply type pwd. Recently, I found starship which has themes and adds another line just for the path. It colorizes the output and highlights whenever I’m in a toolbox/distrobox. It is awesome.

  • DefederateLemmyMl@feddit.nl
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    9 months ago

    Do not use #!/bin/sh if you’re not writing bash-only scripts

    Actually #!/bin/sh is for bourne shell compatible scripts. Bash is a superset of the bourne shell, so anything that works in bourne should work in bash as well as in other bourne compatible shells, but not vice versa. Bash specific syntax is often referred to as a “bashism”, because it’s not compatible with other shells. So you should not use bashisms in scripts that start with #!/bin/sh.

    The trouble is that it is very common for distros to links /bin/sh to /bin/bash, and it used to be that bash being called as /bin/sh would change its behavior so that bashisms would not work, but this doesn’t appear to be the case anymore. The result is that people often write what they think are bourne shell scripts but they unintentionally sneak in bashisms… and then when those supposed “bourne shell” scripts get run on a non-bash bourne compatible shell, they fail.

    • gnuhaut
      link
      fedilink
      arrow-up
      3
      ·
      edit-2
      9 months ago

      Oh I wanted to say, “Do not use #!/bin/sh if you’re not writing bash-only scripts”. I think I reformulated that sentence and forgot to remove the not. Sorry about the confusion. You’re exactly right of course. I have run into scripts that don’t work on Debian, because the author used bashisms but still specified /bin/sh as the interpreter.

      • DefederateLemmyMl@feddit.nl
        link
        fedilink
        English
        arrow-up
        3
        ·
        9 months ago

        Oh I wanted to say, “Do not use #!/bin/sh if you’re not writing bash-only scripts”

        Hah, I was wondering if that was wat you actually meant. The double negation made my head spin a bit.

        I have run into scripts that don’t work on Debian, because the author used bashisms but still specified /bin/sh as the interpreter.

        The weird thing is that man bash still says:

        When invoked as sh, bash enters posix mode after the startup files are read.
        ...
        --posix
            Change  the  behavior  of bash where the default operation differs from the POSIX standard to 
            match the standard (posix mode). See SEE ALSO below for a reference to a document that details 
            how posix mode affects bash's behavior.
        

        But if you create a file with a few well known bashisms, and a #!/bin/sh shebang, it runs the bashisms just fine.