News for hackers. Stuff that matters.
Re:A surprise with how ' ' handles its program argument in p... by Crestwave on Wednesday November 19, 2025 @11:50PM (#45989092)
`#!/usr/bin/env bash` is the most portable form for executing it from $PATH
Re:A surprise with how ' ' handles its program argument in p... by hamandcheese on Wednesday November 19, 2025 @11:56PM (#45989138)
Is this meaningfully more portable than #!bash though?
Re:A surprise with how ' ' handles its program argument in p... by saurik on Thursday November 20, 2025 @12:17AM (#45989232)
This mechanism doesn't do a PATH lookup: #!bash would only work if bash was located in your current working directory.
Re:A surprise with how ' ' handles its program argument in p... by tombert on Wednesday November 19, 2025 @11:58PM (#45989150)
In a sibling thread someone pointed out that #!bash doesn't actually work if you're calling it from bash, and appears to only work with zsh.

I just tried it and they were absolutely right, so `#!/usr/bin/env bash` is definitely more portable in that it consistently works.

Re:A surprise with how ' ' handles its program argument in p... by Ferret7446 on Thursday November 20, 2025 @08:02PM (#46000027)
I raise you a https://www.felesatra.moe/blog/2021/07/03/portable-bash-sheb...

Pedantic, but "#!" and "portable" don't belong in the same sentence

Re:A surprise with how ' ' handles its program argument in p... by Crestwave on Monday December 01, 2025 @04:19AM (#46105230)
The script you posted is only portable in theory and not in practice. Executing it while using a non-POSIX shell like Elvish (even without having it as a default shell) makes it immediately fail.

Meanwhile, `#!/usr/bin/env` is completely portable in the practical sense. Even systems with non-standard paths like NixOS, Termux and GoboLinux patch in support for it specifically.