Search code examples
fish

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


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.


Solution

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