I will repeat what others have told you here already. Hopefully you get it when it is repeated a second time. There are several (separate) points:
1) DO NOT MODIFY FILES WITH "echo ... >>"
It doesn't matter if you write:
or
you should NEVER do that to ANY file. The reason is you have no clear conception of what the files content is before or after. This is why you should use an editor (nano, vi, whatever - just use an editor instead of your imagination, because your imagination is not good enough for the task).
It is true that it is possible to manipulate files that way. But you have to be absolutely sure what you are doing - and you are NOT. Do not try experts methods as long as you are not an expert. You do not start figure-skating with the triple toe-loop and expect staying unharmed if you try it nevertheless.
2) Manipulate your PATH correctly
The PATH-variable is a list of directories, separated by colons:
This list of directories is searched for executables. Notice the profound difference between:
and
The first one replaces the current value of PATH with "/some/dir", the second one adds "/some/dir" to the end of the current value. In light of what i said above: which do you think helps better achieving your goal? Attention, this was the bonus question!
3) Modify vital system configuration carefully
The way you modify starting- and environment-scripts has a "fire-and-forget"-style to it. An experienced expert always is aware that he could do something wrong and therefore secures a way to step back before he tries anything.
You goal might - ultimately - be to modify your .bashrc. In your shoes i'd first create a copy of the existing - and known to be working - file, like:
and only then modify it. If - like in your case - the modification does not turn out to be correct - you simply copy it back and start over! Better yet, you do not only make a copy but try it out on the commandline before even attempting to modify any file. This way you can simply log off and log on again and have your environment restored to be intact:
Btw., this not only applies to modifications of .bashrc. This is the mindset of a truly responsible sysadmin: whenever you do something, you first wonder what might go wrong doing it and plan/take precautions to alleviate such possible problems. Then, after careful planning, you do it. Finally, when everything went seemingly well, you test what you have done: if it really had the desired effect, if it didn't have any unwanted side-effects, if it did have any other effects (they may not be unwanted, but it is good to know they are there), and so on!
Experienced swimmers first test the waters and only then jump in with bravado. Otherwise your head might be in for an unpleasant surprise if the water is only 1ft deep instead of the expected 10ft, if it is ice-cold instead of well-tempered or whatever the unexpected circumstance might be.
Finally, to come back from the abstract musings about work in general, some concrete observation: setting the PATH is done in bashrc, either in /etc/bashrc if the setting should be system-wide or in ~/.bashrc in a certain home-directory if it only for a specific user. The reason this does NOT BELONG to a profile is that ~/.profile is called from the login process when you login. ~/.bashrc is called whenever a shell starts. If you log in once and then start 5 shells. You profile is executed once, but the bashrc file is executed anew for every instance of the shells you opened.
As pointed out earlier,
in .bashrc can end up in multiple :/dir/to/add:/dir/to/add:..., because each nested shell runs another .bashrc at start-up.
Nothing to worry about, if there is no maximum length exceeded.
But isn't it worth to consider .profile as the better location? .profile is only run once in the first shell (login-shell). PATH is environment: a child shell will inherit it, nothing is lost.
Strange concepts like "dbus" in Linux break the native Unix parent/child relationship, but try to emulate it.
And don't the GUI/desktop/VNC/whatever logins run a login-shell?
@MadeInGermany: good question! My answer is a firm: that depends. ;-))
As i said earlier, .profile is executed once for every login(-shell), .rc-files (depending on the login shell ~/.kshrc or ~/.bashrc or even something else) are executed for every new shell. Whatever you want to execute every time you log in goes to the profile, whatever you want executed for every new shell goes to the rc-file.
Quote:
Originally Posted by MadeInGermany
As pointed out earlier,
in .bashrc can end up in multiple :/dir/to/add:/dir/to/add:..., because each nested shell runs another .bashrc at start-up.
True. In some environments i put a sort-of "reentrancy-protection" into my .kshrc to prevent that:
But i have to say that nested shells happen rarely at my workplace. My typical environment consists of an X-server, mwm on top and many xterms. The login session starts the window manager via exec, so the shells in the xterms are each first-level shells because the login-process was replaced by the mwm.
I do not use "desktops" like KDE, GNOME or whatever they are called if i can avoid it, so i can say nothing about how these work.
Are there any advantages of doing one over the other in your .bashrc? They both seem to do the same thing.
HISTFILESIZE=10000
HISTSIZE=10000export HISTFILESIZE=10000
export HISTSIZE=10000 (4 Replies)
I have modified the .bashrc. The problem is that when I write a long command,
it does not write on the next line but continues to write on the same line.
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for... (1 Reply)
Could someone please tell me how to unset your .bashrc? I have tried all of these. I can't find anything useful from google.
unset -f .bashrc
unset .bashrc (9 Replies)
I am trying to do some changes at bashrc file located at /etc directory of my server. First I tried to edit bashrc via FTP downloaded on my pc changed it and loaded back, but it seems like changes are not reflecting.
Therefore I tried to change it via putty shel using vim bashrc command. but... (4 Replies)
i have made a few changes to my bashrc file...have set a few environmental variable that my shell scripts use. Is there any way that these changes can reflect in evryone else's bashrc who are in the network or do all of them have to copy those changes to their own bashrc file. (2 Replies)
hey guys,
i've tried countless times to do this and have come up with:
find / type -f ".bashrc" -exec grep PS1 '{}' \; 2>/dev/null | ls -l
which tells bash:
find all the files in the system with the name .bashrc and look for modifcations to PS1 and terminate and rediret error msgs... (8 Replies)
Hi,
I was instructed to find all the .bashrc files on my system, that MODIFY the PS1 varaible.
here is what i've come up with so far:
ls / .bashrc -print
woo.
But thats not all. I need to display the full file name ( Including the full path ) and protection.
- I can display... (4 Replies)
hey guys,
Im trying to find all my .bashrc files in the home directory.
~/etc/bash.bashrc is the only thing i can find but its outside of my /home
Could the files be hidden? I want to see all my .bashrc files in my /home structure... <cries> (5 Replies)
Hi, I come into unix with csh, but i switch to bash . I want to clear my command history for each session, history -c, but for some reason this doesn't work in the .bashrc file. I know that the file is running after I type bash on my csh command line because I get the hello back. If I am already... (1 Reply)
:) as soon as i installed my software a couple of weeks ago..
(fedora core 2 vs, 2.6.8-1.521) i decided to switch the shell to sh shell and i know that .bashrc is the bash profile file(???) i want to use the sh version of the same file and make it the main profile file.. how can I switch it and... (3 Replies)