@derek I seriously cannot determine if this is sarcasm or not. btw, why youtube? Linking to Odysee would better promote it and things it stands for.

@derek i thought script being able to run on /bin/sh ran in any shell? what about bashisms and fishisms? with `#/usr/bin/env sh` would the script be more certain to be compatible without having to install a specific shell?

@nergal @derek That's the basic idea. IIRC POSIX specifies that /bin/sh should be a sh-compatible shell and scripts using it should only use sh's functionality. There was a nice Debian blog post on how they switched that symlink to dash for increased performance and on the way discovered a bunch of bashisms that made them non-POSIX-compliant.

@derek only a problem on bad distros, good distros have /bin/sh linked to dash

@derek /bin/sh exists and it can be whatever you want it to be. but /bin/sh really wants to be POSIX compliant. please don't bully /bin/sh by linking non-POSIX shells to it :(

i use ksh btw

It's the original shell but these days usually a symlink to bash or dash.
@derek This video is hilarious, from the dumb style to the deliberately bad misinformation.

@derek I'm pretty sure it's a mistake to symlink /bin/sh to a non-POSIX compliment shell.

@rob @derek Both dash and bash adjust their behaviors when called as /bin/sh.

@nanook @derek My understanding is that only commands that are POSIX-compliant will work when either of those shells are called with /bin/sh.

@derek Huh, and here I thought that /bin/sh WAS an actual POSIX-compliant shell...but if it's just a symlink to whatever the hell you have for shell then what exactly is the point of all that nonsense?

@Zeth @derek No but for systems with bash or dash it is, other shells like csh and tcsh can not pretend to be /bin/sh.

@nanook @derek not to mention the fact that POSIX standard is lowest common denominator across multiple systems, which seems to me like fundamentally flawed design - because rather than improving on the shortcomings, you instead limit the potential of more advanced implementations...

@nanook @derek perhaps I'm not seeing the full picture though.

@Zeth @derek No, you can write shell scripts #!/bin/bash to take full advantage of bash, or #!/bin/tcsh to use terrible cshell, or #!/bin/perl to use perl, etc.
@Zeth @derek
No, /bin/sh is supposed to be POSIX-compliant. Linking a non-compliant shell to it is his fault, not script writers' :^)
Now do one about how you prefer `less` to `cat` so you just make the following change on your system.

# rm /usr/bin/cat
# ln -s /usr/bin/less /usr/bin/cat

@derek

@derek /bin/sh is a *real* shell with a *real* specification and multiple, compatibile *real* implementations. You should always try to write POSIX compliant scripts if you don't have good reasons to do otherwise. Also, how could /bin/sh be the user's default shell? You can have multiple users with different login shells on your system, you know?

@dalz @derek Yes but the #!/bin/sh tells the operating system to use /bin/sh to execute that code REGARDLESS of what the users login shell is.

@nanook @derek which is exactly what you want, since the user's shell could be bash, zsh, fish, ksh, oil, emacs, /usr/bin/nologin or anything else!

@derek
Alpine doesn't come with bash. Nor does OpenBSD. Nor OpenWRT, nor embedded linux systems, nor initramfs environments. If you want to write a script that is portable and runs in all those systems, you write it in scrictly posix-compliant shell. That's what /bin/sh is for.
@derek
Also, to change the default shell for a user, just use chsh. /bin/sh should always be symlink to a posix-compliant shell in any sane system
Sign in to participate in the conversation
DistroToot

A mastodon instance created by Derek Taylor, creator of the DistroTube channels on YouTube and LBRY. Derek is an advocate for free and open source software.