-
Notifications
You must be signed in to change notification settings - Fork 3.3k
more rationale for not using #!/bin/bash? #82
Comments
These are the only two reasons really. It's more about portability than anything else. |
https://en.wikipedia.org/wiki/Shebang_(Unix)
It won't find recognition in most security guides.
I want to say that I can have several versions of the same program and by changing the link, I can redirect to the appropriate version of the program or to another location. And it's probably safer. PS. please don't look at rwx permissions. |
Sure, there are times when a direct path is preferred. Keep in mind that what I write in this guide is not absolute and you may have good reasons for doing task a differently. I've added a note to the README in this location. |
This has become kind of a standard now, though. Systems like Termux and Haiku which don't have it there seem to have checks to emulate it. |
Do you mean /usr/bin/env? I'm guessing that someone knows little or has not come up with an idea run script like this Or someone does not stick to the standard and came up with a brilliant idea Or it was just an example from other program with a similar problem. I think you can use for your own needs |
It's often used, but systems such as FreeBSD and OpenBSD have it in
You don't need to make everyone use it in order for it to work. You could say that about a lot of things; I mean, this whole project is for pure Bash tricks, when many use external programs instead. Also, lots of people already use it; it's not a new concept, nor Bash-specific. It's also used with Python, Perl, Ruby, etc.
What?
If you put another Bash higher in the PATH you clearly want it to be launched instead, no? I don't get what you mean by this. For example, the default Bash's version in macOS is 3.2. Thus, many who use it would install a more recent version to I would say it's the other way around: it's fine to use You don't seem to really care about portability, though. It's old, so I don't know if you've changed your mindset since then, but you forcibly require |
I know only Linux, I don't know BSD systems. For Linux I know only:
Exist also Unix standard (Linux and BSD) However
It seems to me a much smarter solution, than Maybe I was received wrongly.
but I do not recommend using #!/usr/bin/env bash because it is more problematic. |
As far as I know, yes, but only for the base system, which Bash is not part of; all others go into
Are you sure that it isn't talking about
I mean, you don't have to edit anything if you just use |
FHS mentions solution for all programs. |
Again, I'm pretty sure that programs outside of the base installation (Bash isn't, but env is, of course) are in EDIT: Also, I was talking about this part of the quote:
It seems to be talking about |
It doesn't matter for me, if it's not there, you can always create a symbolic link to the right program in system, as mentioned in the guide. |
I am guessing that there are no problems with sh.
But I don't know if this is also a standard for all BSDs. |
That is not a good solution; I'm assuming that the guide meant that for packagers.
No, there aren't, as I mentioned earlier. |
I do not know what you want to achieve. |
...I think you'll find Some history may be helpful to understand the situation. The UNIX/BSD systems, etc, that don't use bash as default It is worth noting, the rather complicated invocation paragraph |
Reopening this as it's a good discussion on the topic. |
I don't want to write too much but some things need explanation and are not directly related to the topic.
For now, I see only one your problem.
Maybe symbolic links don't cure all things, I can't check it. Probably a similar scheme (packgage with missing dirs and links) was used in linux distributions which use repositories from various Linux distributions, but I have never had time to get to know them more, so I can't give guarantee. Not related to the topic also.
And I know from own experience that also in programs, for example in the login manager. |
It works, yes. But you're suggesting every BSD user that wants to run Bash to use a hack messing with their system directory instead of simply using
The BSDs will not place it there. They have been around for a long time; why do you think they'll change it now?
The foreign standard is to use And what of macOS? It already has a And what of other interpreters? Do you suggest for users to make links for Python, Perl, Ruby, Lua, Tcl, etc., too? Also, I want to stress again that using The main problem with using
You can use it, and you should if possible, but it has less features than Bash. You may want to check out the pure sh bible. |
Do you mean transferring the bash to /usr/bin? I will give a little different example.
So I realize that every system distribution may want to install the program in its / own location.
And when I noticed it, I know that it is problematic for developers, because they have to write an installation script that links all installed files. Returning to env. I don't understand one more thing.
Where from FHS http://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html#usrlocalLocalHierarchy
BSD systems use other FHS? |
? Even if they do, most scripts currently use And again, they won't. Also, I would say that there is a better solution: using
What? When you want to use
FHS is a Linux standard, as far as I know; I mean, the URL is from linuxfoundation.org. |
Now you see, I've written scripts all my life in a dangerous way, and I didn't realize it. 😄 |
I also mentioned the possibility of building a package (separate) for program(s) portability. Because not everyone will want to have unnecessary additional directories and links. You will not force anyone to use env either. |
This isn't really up for debate at all. There are pros and cons to both and there are clear reasons for why you'd use one over the other. Utilizing both of these methods covers every use case I can think of and I don't see how an alternative could be more portable, simpler, easier to use or more robust. At the end of the day, if you want 100% guaranteed POSIX portability and compatibility, write your scripts in POSIX In my eyes, this is a "solved" problem. |
@Crestwave For example, I created "test" script with line echo $PATH This running script shows my modified $PATH variable.
Bash with option login.
Example with env
Env with option invoke.
Edited |
FWIW, |
@abathur
So I'm guessing you can only use scripts compatible with sh. I'm guessing if you want run script only compatible with |
They would also prefer to get rid of |
@Crestwave's point is the most valid (and painful). We support a large set of scripts, and can't go above bash 3.2 features because MacOS. AFAIK, Homebrew installs a newer version of bash into a directory which precedes /bin on the PATH, so the /usr/bin/env is an essential trick for people using modern bash on this technologically retarded system. |
Good lord the comments in this thread. Should make it an interview question... tl;DR - Google et all can use env all they want, they're an exception in that they have full control over their environment. To use them as an example of why we all should follow is ... stupid. For the record:
To say the use of env is universal, is equally stupid. Fact that 6 of those are python should say where this FUD comes from. Use it in your own personal scripts, stay the hell away from system. |
This is a bit dramatic in the context of choices marked
I'm not sure why you think the contents of /bin have any bearing on a portability recommendation. The overwhelming majority of all bash scripts ever written will not see the inside of /bin. I have 0 bash scripts in /bin on either system in front of me.
🙄
Neither of these is the point. Use whatever you want in your personal scripts. If you're writing for an audience, use If PATH manipulation affecting which bash interprets readonly scripts is this far up your list of concerns, I assume you're already doing something like auditing these scripts and any subsequent scripts/binaries invoked to ensure all executables are invoked using the absolute paths of a verified readonly executable, or at least patching them to use fixed PATHs? |
Because there's' nothing "less right" about it. Why are you implying otherwise?
You have that backward and fail to understand why.
I agree, any competent admin won't. You're implying env is better, stupid people will follow this advice, as indicated above.
I don't know what that even means... env uses the PATH... by design. |
Hey @dylanaraps, I think is super useful, thanks for making it! I was wondering if you could add a bit on your rationale for using
#!/usr/l/bin/env bash
instead. This is generally my thoughts: https://stackoverflow.com/a/55927235, but I'm not a bash expert.The text was updated successfully, but these errors were encountered: