~/.bashrc not sourced in a new lxterminal window
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.
Solution 1:
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.