1

Some of the similar questions don't quite seem to match with my question. What I'm trying to do is to have .bashrc (or similar) to only run certain custom commands when I launch it from within the GUI (Xfce), but not in the initial login screen.

Some details:

  • Ubuntu 16.04 Virtual Machine (VirtualBox 5.2.10) on Windows host
  • When I launch it, I use the user vagrant in the boot login screen
  • I normally launch Xfce manually with sudo startxfce4
  • Then once the GUI has loaded, I launch a terminal (Terminator) and it runs for user vagrant

So what currently happens:

  1. I launch the VM
  2. It asks for user in the boot screen
  3. Then it will use the .bashrc of that user and already does the commands I have there. I would want them to only run when I use the GUI terminal (This is my question - how to do that?)
  4. Start the GUI
  5. Then when I launch the terminal in the GUI, it will run those same commands again.

What I would like to happen:

  1. Launch the VM
  2. Login as the user - and do not run the specified commands yet
  3. Start the GUI
  4. Launch the terminal from GUI - now it should run the commands automatically

So, basically I'm looking for some kind of system flag that tells it is not running on GUI. Does such exist? I imagine you could check it from somewhere, like xfce status or similar?

The key thing is, I would like it to run automatically instead of running a script from PATH, because that is easy to forget and you might spend quite some time debugging why something doesn't work, only to notice you forgot to run the prerequisite commands.

Thanks!

1 Answer 1

1

The shell variable TERM

I think you can check the value of the shell variable TERM with 'if' or 'case' statements to control what to do in text screen and graphical desktop environment.

It is already used in the default bash configuration file ~/.bashrc files of Ubuntu Desktop.

  • In Ubuntu 18.04 LTS graphical desktop:

    $ echo "$TERM"
    xterm-256color
    

    This may vary between versions of Ubuntu. Check in your installed system.

  • In Ubuntu 18.04 LTS text screen:

    $ echo "$TERM"
    linux
    

Demo example

Add an 'if' statement to the bash configuration file ~/.bashrc

It is a good idea to make a backup copy before doing it.

cp -p ~/.bashrc ~/.bashrc.backup

and then add something like the following lines (modified for your particular purpose) at the end of the file ~/.bashrc

if [ "$TERM" != "linux" ]
then
 echo "Do your commands for a graphical desktop"
 ...
 ...
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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