Running commands with local variables on the fish shell
When using the Fish shell, you may need to run commands with local variables, like the following (Bash):
RAILS_ENV=staging rake db:migrate
This doesn't work in Fish, as setting a local variable follows another syntax, using the set
command.
You can achieve the same result with the following syntax:
begin; set -lx RAILS_ENV staging; rake db:migrate; end
The flags set the variable as local (l
) and export it to child processes (x
). You may not need the latter depending on the command you want to run.
It's a bit verbose, so you can define a function to make it easier
function v
set -lx $args
end
Then you can type:
begin; v RAILS_ENV staging; rake db:migrate; end
Written by Claudio Ortolina
Related protips
1 Response

Can't you just run env RAILS_ENV=staging rake db:migrate
or (since rake allows that) rake db:migrate RAILS_ENV=staging
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#