I'm a relatively new user to Linux, so bear with me. I'm currently taking on the Linux From Scratch project, and I have reached a point where it calls for opening a new terminal with certain environment variables. The entire book is intended to be performed in command-line mode, which I am able to access with Ctrl+Alt+f1 (or f2 or f3 or...), but primarily for comfort I prefer to use a terminal window.

The book, in chapter II, section 4.4, calls for the reader to create a ~/.bash_profile with only one command: exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash, which "ensures that no unwanted and potentially hazardous environment variables from the host system leak into the build environment". I've added to the command a dummy variable Q to ensure that it is functioning properly.

When running Ubuntu in a virtual command line, the script is read as expected, and I have the new terminal with the variables initialized. However, I don't get this behavior if I open a terminal window through the GUI.

Is there any way to open a GNOME Terminal with specific environment variables like what is done by the above exec for the Linux console?

  • add the export into ~/.bashrc and close and reopen the terminal window. and the corresponding ~/bash_profileis called in ubuntu ~/.profile
    – Videonauth
    Apr 22 '16 at 3:31
  • @Videonauth Hm. Why is it that when I have no ~/.bashrc, env still outputs a lot of environment variables? Apr 22 '16 at 3:40
  • because of /etc/bash.bashrc file
    – Videonauth
    Apr 22 '16 at 3:48
  • @Videonauth is there a way to make the GNOME terminal for a specific user ignore /etc/bash.bashrc? Apr 22 '16 at 3:52
  • Yes, make a backup of your bashrc file in your home folder and make an empty one. an empty .profile aswell overrides the default
    – Videonauth
    Apr 22 '16 at 3:54

If I understand your question correctly, what you want is having gnome-terminal behave like a virtual console as far as rc scripts are concerned.

That should be achieved by configuring it to run the shell as a login one.

Edit → Profile Preferences → Title and Command → Run command as login shell

  • Thanks much - This did exactly as I expected, once the new profile was set to be the profile opened with. However- the PS1 variable isn't getting set as expected either here or in virtual console mode. Do you happen to know why? Apr 22 '16 at 15:40
  • What does it look like ?
    – jlliagre
    Apr 22 '16 at 15:46
  • When I enter the terminal the PS1 variable is the standard. ${debian_chroot:+($debian_chroot)}\u@\h:\w\$ Apr 22 '16 at 15:48
  • Never mind, I managed to fix it by setting the variable in ~/.bashrc Apr 22 '16 at 16:00
  • Great. Looking to that file would have been my next suggestion.
    – jlliagre
    Apr 22 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.