So obviously not every system sets to /bin (such as )

If two systems have different install paths, say:
System1:
/home/me/bin/bash
System2:
/bin/bash

How can I write a shell script that allows both systems to be happy? can I do:
#!$BASH
#!which bash
or something across these lines?

I really need to learn Bash properly sometime....

Follow

@gemlog

You mean I can do that in the script itself? Like
#! $PATH/bash
?

I'm not trying to make this script run on two of *my* systems, per se, but on as many machines as possible. I'm wondering what the most portable way to begin a shell script would be. I see
#!/bin/bash
a lot, but I hate it since my machine has a different location for bash!

@MutoShack No. You can set multiple locations in the path variable for where it searches, in order.
If the actual location of bash itself varies across systems, you're a bit effed.
Here's the one on my home box as an example.

immaculata 15-20:01 ~> echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/gemlog/bin/vc:/home/gemlog/bin:/home/gemlog/bin:/home/gemlog/bin/vc:/home/gemlog/bin

@gemlog @MutoShack Shebangs require full path to the interpreter, maybe followed by some options.
$PATH and other environment variables may help with wrapping the interpreters into an `env`, but the path to the `env` itself is still hardwired.
Guix and Nix developers couldn't come up with anything better than patch the shebangs or guarantee the paths are actual.

Sign in to participate in the conversation
Functional Café

functional.cafe is an instance for people interested in functional programming and languages.