SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I find when I open bash (I do this by clicking on the Konsole icon of a terminal at the bottom of the KDE screen and maybe sometimes by going into the KDE menu so I imagine I am always using the same version of Bash) I get variable behaviour.
For example sometimes the prompt is bash-4.3$ while other times it gives the root to the directory I am in and also tells me which user I am.
The output to commands like ls changes too. Sometimes I get it all in black (or at least blue) and white other times the files and directories are colour coded.
Today it seemed variable. I have pasted the bash session below which left me a bit confused:
bash-4.3$ which javac
/usr/lib64/java/bin/javac
bash-4.3$ su
Password:
bash-4.3# which javac
which: no javac in (/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin)
bash-4.3# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
bash-4.3# su steve
bash-4.3$ echo $PATH
/usr/local/bin:/bin:/usr/bin
bash-4.3$ which javac
which: no javac in (/usr/local/bin:/bin:/usr/bin)
bash-4.3$ whoami
steve
bash-4.3$
It seems odd that the first time as user steve I issue whereis javac it returns '/usr/lib64/java/bin/javac'. Then I change to user root and perhaps understandably it sais it cant find it in root's path. Then I su back to steve and reissue the command and now it sais it cant find it in steve's path.
I have just read the man page for which and it seems that which will only return the path to directories that are in the user's $PATH. Perhaps I misunderstood that because '/usr/lib64/java/bin/javac' was returned but it does not appear when I do echo $PATH.
Anything to push me in the right direction for understanding this would be very much appreciated, Steve
Setting up a ~/.bash_profile that runs ~/.bashrc as described in the second of the links that ponce provided you with is definitely the way to go. Some of the stuff in /etc/profile(.d/*) such as setting dircolors, PS1, and command aliases really belong in ~/.bashrc.
I have to say: not, it is not unpredictable, but it is the expected behaviour although it is a bit surprising.
You need to understand how the environment is set during login, by su and/or su - (and for example using ssh, opening a new terminal ....). Remember every and each shell has its own environment.
one more resource: man bash, look for invocation
It seems odd that the first time as user steve I issue whereis javac it returns '/usr/lib64/java/bin/javac'. Then I change to user root and perhaps understandably it sais it cant find it in root's path. Then I su back to steve and reissue the command and now it sais it cant find it in steve's path.
In addition to what ponce and GazL provided, if you were to run exit from your root session rather than su steve, it would've taken you back to your original login with the PATH variable set to include javac.
As above, you must "su space dash (hyphen)", in order for su to run that user's login script:
Quote:
su -
To have the Konsole run a "login" shell by default (as I prefer), in Konsole click Settings > "Manage Profiles" > Select "Shell" & click "Edit Profile...", and change "Command:" to read:
Quote:
/bin/bash -l
(that's a lowercase [ L ], not an uppercase [ i ] - the font used by Firefox makes it hard to distinguish the difference) ...then click "OK".
The "-l" parameter tells bash to act as a "login" shell.
Thanks very much for your help. It looks as if the initial non login shell has the path to javac but the login shell which I get to with su -l does not have the path. I guess I need to add that path to my $PATH variable.
It looks as if the initial non login shell has the path to javac but the login shell which I get to with su -l does not have the path. I guess I need to add that path to my $PATH variable.
I think you are making a little confusion, it's exactly the opposite: the login shell that you get with "su -l" should have the correct PATH variable and the non-login one no.
you have described this exact situation in your first post.
that's why I suggested to read the man page (invocation) to understand what's happening. What is the login shell .... It is explained perfectly, I could only copy it....
Woops! Thanks for putting me right. I guess the situation is that when I start up the computer I do log in right at the beginning and then go into KDE. Then I open a konsole window and am in a log in shell. If I issue su without a hyphen I am taken out of a login shell even though in one sense of the word login I am logging in (ie providing a username and password and being admitted to some functionality). I need to read up more on this. I did read the references given but a lot is not sinking in unfortunately. Some is!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.