bash and fish scripts are not compatible, but I would like to have a file that defines some some environment variables to be initialized by both bash and fish.
My proposed solution is defining a ~/.env
file that would contain the list of environment variables like so:
PATH="$HOME/bin:$PATH"
FOO="bar"
I could then just source it in bash and make a script that converts it to fish format and sources that in fish.
I was thinking that there may be a better solution than this, so I'm asking for better way of sharing environment variables between bash fish.
Note: I'm using OS X.
Here is an example .env
file that I would like both fish and bash to handle using ridiculous-fish's syntax (assume ~/bin and ~/bin2 are empty directories):
setenv _PATH "$PATH"
setenv PATH "$HOME/bin"
setenv PATH "$PATH:$HOME/bin2"
setenv PATH "$PATH:$_PATH"
PATH
fix for fish work with paths with: spaces? newlines? other things to look out for? – Tyilo Dec 28 '14 at 23:28[
is a builtin in both bash and fish, so PATH should not need to be set correctly to use[
. The setenv sample should work with all characters in PATH except for colons and newlines. – ridiculous_fish Dec 30 '14 at 00:35tr
with/usr/bin/tr
I and using the.env
file provided in my question, I get a lot of errors when starting fish. I don't think the PATH handling is correct. – Tyilo Dec 30 '14 at 00:39tr
syntax would betr ': ' '\n\n'
ortr ': ' '[\n*]'
here.echo -- $arg...
would be more correct, though unlikely to make much difference in practice. – Stéphane Chazelas May 23 '20 at 07:11