In bash, I can do EDITOR=vim crontab -e. Can I get similar effect in Fish shell?
5 Answers
Don't see why this shouldn't work:
env EDITOR=vim crontab -e
That bypasses the shell completely.
- 1,021
begin; set -lx EDITOR vim; crontab -e; end
- 62,879
-
5
-
oddly, this doesn't work for me. I'm calling a ruby script, and ENV doesn't pick up the variable I'm setting:
set -lx date '12/04/2012'– Duke Dec 07 '12 at 23:13 -
@Duke: It works for me.
begin; set -lx date '12/04/2012'; ruby -e 'puts ENV["date"]'; end– Dennis Williamson Dec 08 '12 at 00:49 -
11In the meanwhile this has been answered in the Fish FAQ: http://fishshell.com/docs/current/faq.html#faq-single-env – harm Apr 03 '14 at 09:09
-
4
That is from the Documentation
SOME_VAR=1 command produces an error: Unknown command "SOME_VAR=1".
Use the env command.
env SOME_VAR=1 command
You can also declare a local variable in a block and that would not bypass the shell
begin
set -lx SOME_VAR 1
command
end
- 251
Starting version 3.1, you can use the same syntax used in bash (EDITOR=vim crontab -e).
PR introducing the feature: https://github.com/fish-shell/fish-shell/pull/6287
- 161
depending on a definition of be function, this can fail
begin
set -lx RAILS_ENV staging
be rails r "p ENV['RAILS_ENV']"
end
In order for it to work:
function be --description 'Runs bundle exec' --no-scope-shadowing
bundle exec $argv
end
Please, see the explanation of --no-scope-shadowing option
-S or --no-scope-shadowing allows the function to access the variables of calling functions. Normally, any variables inside the function that have the same name as variables from the calling function are "shadowed", and their contents is independent of the calling function.
- 121
- 3
env SOME_VAR=1 echo $SOME_VAR– lmsurprenant Nov 01 '17 at 22:50