If two systems have different #BASH install paths, say:
How can I write a shell script that allows both systems to be happy? can I do:
or something across these lines?
I really need to learn Bash properly sometime....
@MutoShack what about using something like #!/usr/bin/env bash ?
It's weird - GuixSD doesn't come with a /usr directory, it has a /gnu directory (I can add a /usr/env if I wanted to, but I want my software to be as out-of-the-box as possible, without the need for userside customization).
Thanks, though! /usr/bin/env, although not a catch-all in my case, is way more portable than the usual (and sadly ubiquitous) #!/bin/bash
@MutoShack well GuixSD adventures is a game that I hope to play soon
Can't you just set $PATH for both dirs?
You mean I can do that in the script itself? Like
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.
@MutoShack #Guix does patch the shebangs in all the scripts, so they always point to the specific path in the store.
While #Nix is more lax and just keeps the standard path for the shell (not a good idea actually).
Generally, you write a script with some standard path (#!/bin/sh), and a Guix/Nix expression that would be used to run it in some specific environment (e.g. `guix build` and `nix-build`), and point it to the correct shell by the way.
functional.cafe is an instance for people interested in functional programming and languages.