Script in repo requires different shell-script headers for different computers

75 Views Asked by At

I use nixos and my bash path is /run/current-system/sw/bin/bash, therefore I require a shell-script header of

#!/run/current-system/sw/bin/bash

My colleagues use macOS and they require the more standard shell-script header of

#!/bin/bash

There are some scripts in our git repository which I alter in order to run our repo on my machine. I currently deal with this via profuse use of git stash. What is a better way?

There may be some git feature for somehow toggling these changes, setting the repo for use on my machine, and I would be interested to hear about that. Also would be interested to hear how I might edit the script to work unaltered on both types of machine.

1

There are 1 best solutions below

1
On

You can fix this by using:

#!/usr/bin/env command

But you need to be aware that the main disadvantage of using this approach is that it will call the first <command> that your $PATH returns.

For example, if using

#!/usr/bin/env python

It could return either python2 or python3, depending on what your $PATH returns first.