Is there a way to prepend a command with a variable assignment like in bash?

StackOverflow https://stackoverflow.com/questions/22819577

  •  26-06-2023
  •  | 
  •  

Pregunta

In bash one can write

CFLAGS="-O2" rvm install 2.0.0

to run rvm with that specific CFLAGS . Is there anyway to do the same in fish shell?

I know about set -x but that is not exactly the same as the environment variable will be set for the whole session instead of just for that command.

¿Fue útil?

Solución

According to the fish FAQ, either use:

env CFLAGS="-O2" rvm install 2.0.0

(which will not work for fish builtins or functions, only external commands), or

begin
    set -lx CFLAGS="-O2"
    rvm install 2.0.0
end

(which is a little clunky; there are proposals for improvement on GitHub issue #438).

Otros consejos

You can use the env command for this:

env FOO=BAR command

Will run command with env variable FOO set to BAR.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top