3 ms·
I haven’t seen a shell script in ages that was missing the shebang. Is this common in some places? I’ve started to write dash scripts because that seems to be
by hibbelig 5y ago
I haven’t seen a shell script in ages that was missing the shebang. Is this common in some places?
I’ve started to write dash scripts because that seems to be reasonably posix and bash on macOS is ancient.
- IggleSniggle 5y agoI don’t think I’ve ever seen a script written without the shebang. Btw, you can get around the ancient bash in macOS by installing a more modern bash and invoking with /usr/bin/env bash as your shebang. Not sure if that’s a great idea, mind you, but if you’re already writing scripts in something non-portable, it’s an option.
- traviscj 5y agoYeah thing $T _might_ (but probably won’t) happen, so the idea is automatically terrible.
- maccard 5y agoThere are hundreds of sh files on github that don't have a shebang. Just because you don't write them and your colleagues don't doesn't mean they don't exist in the wild.
- IggleSniggle 5y agoI didn’t mean to imply that they didn’t exist nor that it might not be important to account for them in some contexts. I meant only to convey my own personal experience: that it had never occurred to me that I might need to account for a missing shebang, since providing an interpreter for a script via shebang is all I have ever personally encountered.
- pxc 5y agowait how does the OS even invoke an interpreter without a shebang? If you have to explicitly call an interpreter when you invoke it, then it's no extra work to call bash some_script.sh anyway
- IggleSniggle 5y agoAs I’ve learned in response to this thread, apparently some (but not all) Unixy OSes will run a file marked as executable using /bin/sh if no shebang is supplied.
- pxc 5y agoOh right, I think that's part of how APE[1] works. But I thought the Thompson shell was old and weird, and that it might not support what people use when they write ‘POSIX’ shell scripts nowadays. Anyway it sounds like in that case the OS _doesn't_ know how to run the script, it just assumes `/bin/sh` will do. I always assumed that scripts without an interpreter line were like snippets to be invoked via `source`, from some shell script with knowledge of the context in which it should be used. Anyway, if that's the way it works, the behavior actually isn't a problem for users of Nushell or Elvish or Fish or anything else, since their executables are never installed to `/bin/sh` anyway. Nushell probably gets installed to `/usr/bin/nu`, Fish to `/usr/bin/fish`, and `elvish` can be installed anywhere. So it's still not clear that there's a real problem with un-shebanged scripts when it comes to using a boutique shell for login. — 1: https://justine.lol/ape.html https://justine.lol/ape.html
- maccard 5y agoAny random blog post that you find with instructions to run something in a shell that uses a variable just won't work copy and pasted, you now need to either modify them for your esoteric shell, or wrap them in a script to be ran through bash