Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

(I'm talking about the shell Fish, esp. Fish's Fish.)

For Bash/ZSH, I had ~/.profile with some exports, aliases and other stuff.

I don't want to have a separate config for environment variables for Fish, I want to re-use my ~/.profile. How?

In The FAQ, it is stated that I can at least import those via /usr/local/share/fish/tools/, however I don't really like running that for each Fish-instance.

share|improve this question
up vote 8 down vote accepted

My current solution (see here for a maybe more recent version):

egrep "^export " ~/.profile | while read e
    set var (echo $e | sed -E "s/^export ([A-Z_]+)=(.*)\$/\1/")
    set value (echo $e | sed -E "s/^export ([A-Z_]+)=(.*)\$/\2/")

    # remove surrounding quotes if existing
    set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/")

    if test $var = "PATH"
        # replace ":" by spaces. this is how PATH looks for Fish
        set value (echo $value | sed -E "s/:/ /g")

        # use eval because we need to expand the value
        eval set -xg $var $value


    # evaluate variables. we can use eval because we most likely just used "$var"
    set value (eval echo $value)

    set -xg $var $value
share|improve this answer

If your distribution uses PAM, you could set your environment variables in your ~/.pam_environment file.

share|improve this answer

I tried sourcing .profile on fish startup and it worked like a charm for me.

just do :

echo 'source ~/.profile;clear;' >  ~/.config/fish/

Restart terminal or iterm2, test an alias from .profile to test.

share|improve this answer
Worked for me too! Running MacOSX. – Alexar Dec 6 '15 at 3:33

You can't. fish's syntax is too different from Bourne shell (/bin/sh) syntax. This is the same reason you can't use .profile with other non-Bourne-derived shells, such as csh and tcsh.

share|improve this answer
I don't want to fully execute .profile. I just want to get all exports from there. One easy way would be to egrep "^export" which would be good enough already for me. Another, more correct solution would be this. Also, I e.g. could run this script which probably does something similar. So, there are obviously many ways to do this. With my question here, I was wondering how others have solved this. – Albert Jul 11 '12 at 14:18

You can start Fish from Bash. If you do that, Fish will inherit all environment variables (export FOO=bar) from Bash. At this point, Bash will have already read your .profile (or the like).

bash-3.2$ export TEST="test"
bash-3.2$ fish
cmey@MBP ~> echo $TEST
share|improve this answer

Install dash and add this line to your

env -i HOME=$HOME dash -l -c 'export -p' | sed -e "/PATH/s/'//g;/PATH/s/:/ /g;s/=/ /;s/^export/set -x/" | source
share|improve this answer

You can use Bash to parse /etc/profile and ~/.profile, and then start fish.

  1. Create /usr/local/bin/fishlogin with contents

    #!/bin/bash -l
    fish "$@"
  2. Make it executable

    chmod +x /usr/local/bin/fishlogin
  3. Set it as your default shell

    usermod -s /usr/local/bin/fishlogin $USER
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .