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

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

  •  26-06-2023
  •  | 
  •  

Pergunta

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.

Foi útil?

Solução

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).

Outras dicas

You can use the env command for this:

env FOO=BAR command

Will run command with env variable FOO set to BAR.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top