mimi icon indicating copy to clipboard operation
mimi copied to clipboard

`$SHELL` should be changed to `sh` or `bash`

Open Schweber opened this issue 1 year ago • 4 comments

I have nushell as my user shell, thus the following doesn't work:

run() {
  $SHELL -c "'$1' $(printf "%q " "${@:2}")"
}

I suggest to change $SHELL to sh (if that's safe) or bash.

Schweber avatar Apr 25 '24 09:04 Schweber

I could add SHELL to the environmental variables parsed from the config, e.g. something like

CONFIG_SHELL=$(find_in_config SHELL)
if exists "$CONFIG_SHELL"; then
	SHELL=$CONFIG_SHELL
fi

and then in the config you could write

SHELL: bash

What do you think?

BachoSeven avatar Apr 25 '24 15:04 BachoSeven

Sure, that would work. However, i don't understand the reasoning behind using $SHELL in the first place:

With mimi being a bash script, why not hardcode bash or set bash as the default unless something else is specified? Do you want to pull in environment variables from $SHELL that are not set globally?

Schweber avatar Apr 25 '24 16:04 Schweber

@Schweber You're right, might as well hardcore it.

BachoSeven avatar May 02 '24 18:05 BachoSeven

Use a simple nop assignation: if $SHELL is not set, shell is $0

xplshn avatar May 15 '24 05:05 xplshn

@Schweber You're right, might as well hardcore it.

sh is the only bin available in $PATH on nix/os, we have to patch anything else usually.

medv avatar Aug 05 '24 01:08 medv

@Schweber You're right, might as well hardcore it.

sh is the only bin available in $PATH on nix/os, we have to patch anything else usually.

Sounds like an issue with Nix. Usually projects don't adapt for the one and single exception...

xplshn avatar Aug 05 '24 06:08 xplshn

There was not a counterargument provided for making it bash by default, so I think it was worth adding for fairness. It is not an issue, as much as it is worth noting that bash itself could be considered an opinionated choice under a certain thought process.

medv avatar Aug 05 '24 09:08 medv

It is not an issue, as much as it is worth noting that bash itself could be considered an opinionated choice under a certain thought process.

As much as I might agree with that, the script itself is far from being POSIX-compliant, so I'm definitely not going to make it #!/bin/sh for the time being.

Also, I'm not at all an expert with nix but I imagine it is standard to patch bash scripts when packaging, see e.g. https://ertt.ca/nix/shell-scripts/#orgcdf8a6f

BachoSeven avatar Aug 20 '24 13:08 BachoSeven

As much as I might agree with that, the script itself is far from being POSIX-compliant, so I'm definitely not going to make it #!/bin/sh for the time being.

That's fine. The present value of #!/usr/bin/env bash is the best way in my opinion.

Also, I'm not at all an expert with nix but I imagine it is standard to patch bash scripts when packaging, see e.g. https://ertt.ca/nix/shell-scripts/#orgcdf8a6f

This script is not in nixpkgs and i didn't make a nix package for it on my system. I just downloaded it and added it to my PATH.

The problem was/is, that my SHELL environment variable is set to nu and thus this script failed. The suggested improvement to hardcode bash or employ some other workaround is valid and has got nothing to do with Nixos. It can happen on every other system that has set the SHELL environment variable to something other than bash (zsh probably works as well).

Schweber avatar Aug 20 '24 19:08 Schweber

@Schweber I wasn't responding to you with my last comment, if it wasn't clear from the quote; I was trying to understand @medv's point.

BachoSeven avatar Aug 20 '24 20:08 BachoSeven