What is bashInteractive?

I stumbled upon a very peculiar problem. I wanted to set up a bash autocompletion rule in a bash script, using the “complete” bash builtin. But it didn’t work. Here is an example script

#!/usr/bin/env bash

complete -C /foo /foo

It generates for me

line 3: complete: command not found

which is strange since complete is a bash builtin?
However, if I proceed with

nix-shell -p bashInteractive

it does not complain when I run the script. What is happening here? And how can I make it work without entering a nix-shell this way?

Common stumbling block. For historical reasons, the primary bash attr in nixpkgs is a minimal bash (which lacks interactive features) for builds and scripts. Your config is probably specifying bash where you might want it to be specifying bashInteractive.

That said, I’d argue that The Nix Way is to explicitly specify the dependency for the script so that it doesn’t depend on PATH. I sketched out the main approaches in no-look, no-leap Shell script dependencies

Interesting… and surprising! I had bash specified in my config, I will replace that. Good article by the way, thank you!

1 Like