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

If two systems have different install paths, say:

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

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



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
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

@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é is an instance for people interested in functional programming and languages.