Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I added some lines to my ~/.bashrc like

export JAVA_HOME=/opt/jdk1.6.0_22

I sourced it:

$ source ~/.bashrc
$ env | grep 'JAVA'
JAVA_HOME=/opt/jdk1.6.0_22

Then I created a basic bash script under a folder called scripts in my home:

#!/bin/bash

echo 'start'
echo $(env | grep HOME)
echo $(env | grep LOGNAME)
echo $(env | grep JAVA)
echo 'exiting'

sleep 5
exit

Now, if I launch it directly I get the expected output

$ cd ~/scripts
$ bash 'myScript.sh'
start
HOME=/home/foo/.config
LOGNAME=foo
JAVA_HOME=/opt/jdk1.6.0_22
exiting

However I need to call it in a different way using the following command, and unluckily it doesn't work in the same way:

$ lxterminal --command "bash /home/foo/scripts/myScript.sh"
start
HOME=/home/foo XDG_CONFIG_HOME=/home/foo/.config
LOGNAME=foo

exiting

It seems like .bashrc is not sourced in this way. I tried with .profile too, but with the same result. Is there another file sourced by lxterminal when called with the above command?

The reason why I need this command is because I want to launch these my own scripts through links/launchers I added to the start-menu and they have to be executed on a lxterminal window.

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Try forcing bash to use interactive mode:

lxterminal --command "bash -i /home/foo/scripts/myScript.sh"

This happens because:

  • ~/.bashrc is read in interactive mode;

  • ~/.bash_profile, ~/.bash_login and ~/.profile are read in login mode.

See Invocation in man bash.

share|improve this answer
    
Thanks for the tip: it worked like a charm. And thanks for the man part too ;) Sometimes it's hard to find something when you don't know exactly what to search ... –  Luca Borrione Feb 22 '12 at 13:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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