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:$PATHFOO=barI 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 $PATHsetenv PATH $HOME/binsetenv PATH $PATH:$HOME/bin2setenv PATH $PATH:$_PATH
Share environment variables between bash and fish
bash;environment variables;fish
bash has special syntax for setting environment variables, while fish uses a builtin. I would suggest writing your .env file like so:setenv VAR1 val1setenv VAR2 val2and then defining setenv appropriately in the respective shells. In bash (e.g. .bashrc):function setenv() { export $1=$2; }. ~/.envIn fish (e.g. config.fish):function setenv; set -gx $argv; endsource ~/.envNote that PATH will require some special handling, since it's an array in fish but a colon delimited string in bash. If you prefer to write setenv PATH $HOME/bin:$PATH in .env, you could write fish's setenv like so:function setenv    if [ $argv[1] = PATH ]        # Replace colons and spaces with newlines        set -gx PATH (echo $argv[2] | tr ': ' \n)    else        set -gx $argv    end endThis will mishandle elements in PATH that contain spaces, colons, or newlines.The awkwardness in PATH is due to mixing up colon-delimited strings with true arrays. The preferred way to append to PATH in fish is simply set PATH $PATH ~/bin.