Bash – How to create a GUI application launcher for xfce4-terminal with fish but inheriting the environment variables from bash

bashenvironment-variablesfishxfcexfce4-terminal

If I run fish from a bash prompt, it will inherit the environment variables I have set in my .bashrc and .profile files, including the important $PATH variable. So far so good.

Now, I want xfce4-terminal, my terminal emulator, to use fish instead of bash. I found that it supports a -e command line parameter for that but if I run xfce4-terminal -e fish from a GUI application launcher1 then I don't get the environment variables from bash. What gives?


1 Launching xfce4-terminal from an interactive bash prompt also didn't work but gnome-terminal, who has a similar command line switch did. However, gnome-terminal also didn't get the variables when launched from a GUI shortcut.


Edit: I've since bitten the bullet and just made fish into my login shell with chsh --shell /usr/bin/fish. Its much simpler than what I was trying to do before and it avoids some undesirable effects of running fish inside bash (such as having the $SHELL environment variable set to bash)

Best Answer

When bash is run as a non-interactive shell it will not source the .bashrc file and if you use a graphical display manager then the login shell used to run the GUI launcher commands might not have sourced the .profile file. Thus, commands run using the GUI launcher might not have the desired environment variables set when run.

A workaround I found was to tell the terminal emulator to run bash in interactive mode (with the -i flag) and then immediately run fish inside of it:

xfce4-terminal -e 'bash -i -c fish'
Related Question