kenellis
Posts: 7
Joined: Thu Jan 17, 2013 5:50 pm

Adding to LXTerminal $PATH

Fri Jan 25, 2013 12:37 pm

I'm trying to run a shell script using LXTerminal. I can run the script from the normal command line but when I try and run it from LXTerminal i get 'command not found'. If I then add the path of the script to the $Path it works fine, but when I try again in another session the path is no longer there and I get the error message. How can I permanently amend the $PATH of LXTerminal, please?

Ken Ellis

dr_d_gee
Posts: 84
Joined: Fri Jan 04, 2013 1:30 pm

Re: Adding to LXTerminal $PATH

Fri Jan 25, 2013 1:55 pm

Put the statement in .bash_profile in your home directory (this file should already be present but won't show in file manager unless you opt to "show hidden files").

The statement you would need to add would be similar to what you would type in at the prompt.

Code: Select all

export PATH=extra_bit:$PATH
where extra_bit is the path you want to add (you could add it to the end of the path instead of the beginning if you wanted).

kenellis
Posts: 7
Joined: Thu Jan 17, 2013 5:50 pm

Re: Adding to LXTerminal $PATH

Fri Jan 25, 2013 4:03 pm

I don't have a .bash_profile file in my home directory /home/pi. I have .profile and .bashrc files. I added the following to the file .profile : 'export PATH=$PATH:/home/pi/Scripts', but I still got 'command not found'.

The script I am trying to run is:
#!/bin/bash
echo "Please enter backup details."
read backupDetails
echo $backupDetails

I am running it from LXTerminal.

Ken Ellis

User avatar
rpdom
Posts: 15580
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Adding to LXTerminal $PATH

Fri Jan 25, 2013 4:54 pm

Did you try adding that sequence to the .bashrc file? I believe that is the one you need if there is no .bash_profile

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Adding to LXTerminal $PATH

Fri Jan 25, 2013 5:16 pm

The difference is whether you are running a "login shell" or a "non-login shell". A login shell is what you get when you login from the command line. A non-login shell is what you get any other time -- like when you open an lxterminal window. A login shell reads .profile, but a non-login shell doesn't. Both of them read .bashrc.

That's simplified. See the INVOCATION heading in "man bash" for the full story.

efflandt
Posts: 359
Joined: Mon Dec 03, 2012 2:47 am
Location: Elgin, IL USA

Re: Adding to LXTerminal $PATH

Sat Jan 26, 2013 5:39 am

That is something that I was wondering is what actually changes your PATH when you run startx. In my case either my bin gets stripped off, or a default PATH is used and something inserts an invalid path at the start of my PATH (there are some libfm files, but no libfm directory):

Code: Select all

efflandt@tinyproxy ~ $ echo $PATH
/usr/lib/arm-linux-gnueabihf/libfm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games

efflandt@tinyproxy ~ $ ls /usr/lib/arm-linux-gnueabihf/libfm
ls: cannot access /usr/lib/arm-linux-gnueabihf/libfm: No such file or directory

efflandt@tinyproxy ~ $ ls /usr/lib/arm-linux-gnueabihf/libfm*
/usr/lib/arm-linux-gnueabihf/libfm-gtk.so.1
/usr/lib/arm-linux-gnueabihf/libfm-gtk.so.1.0.0
/usr/lib/arm-linux-gnueabihf/libfm.so.1
/usr/lib/arm-linux-gnueabihf/libfm.so.1.0.0
It is possible to open a 2nd lxterminal as a login terminal that sources your .profile (without having to actually log in again):

Code: Select all

efflandt@tinyproxy ~ $ lxterminal -l -e bash
From that lxterminal:

Code: Select all

efflandt@tinyproxy ~ $ echo $PATH
/home/efflandt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
You could fix that at least for the desktop icon by modifying this line like this in ~/Desktop/lxterminal.desktop:

Code: Select all

Exec=lxterminal -l -e bash

kenellis
Posts: 7
Joined: Thu Jan 17, 2013 5:50 pm

Re: Adding to LXTerminal $PATH

Sat Jan 26, 2013 4:30 pm

Thanks guys. Adding 'echo PATH=$PATH:/home/pi/Scripts' to the .bashrc file solved the problem.
The reference to the INVOCATION was very useful for understanding what goes on when bash is called.

Ken Ellis

Return to “Beginners”