JP Vossen via plug on 31 May 2023 20:19:33 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] zsh: command not found:


On 5/31/23 10:36 PM, Gary Duzan via plug wrote:
I always do #!/bin/sh
But I've seen lots of others use #!/usr/bin/env bash
What's the advantage of the latter?

    It gets bash from the PATH instead of whatever specific path you
specify. If you have a non-standard setup, or if you want to use a
different version installed elsewhere, this can be a benefit. It could
also be a security issue if you accidentally put something insecure in
your PATH and you end up running a worm called "bash" from there. I've
seen the end trick most often with python, presumably from the days
when it wasn't standard equipment, so you ended up putting it in
/usr/local/bin or $HOME/bin or something. My NetBSD systems have it in
/usr/pkg/bin.

What Gary said, but also don't use `sh` when you mean `bash`.  That used to Just Work on Linux (but not elsewhere), but since about 2016 it's not reliable on Linux either, due to use of `dash` as `sh` instead of the much larger and thus slower `bash`.

I'm torn on the hard-code vs. `env` approach.  `env` is more portable, but there are possible path/poisoning issues as noted.  `#!/bin/bash` is just easier to type and more familiar.  :-)

Later,
JP
--  -------------------------------------------------------------------
JP Vossen, CISSP | http://www.jpsdomain.org/ | http://bashcookbook.com/

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug