Having more entries in $PATH
doesn't directly slow your startup, but it does slow each time you first run a particular command in a shell session (not every time you run the command, because bash maintains a cache). The slowdown is rarely perceptible unless you have a particularly slow filesystem (e.g. NFS, Samba or other network filesystem, or on Cygwin).
Duplicate entries are also a little annoying when you review your $PATH
visually, you have to wade through more cruft.
It's easy enough to avoid adding duplicate entries.
case ":$PATH:" in
*":$new_entry:"*) :;; # already there
*) PATH="$new_entry:$PATH";; # or PATH="$PATH:$new_entry"
esac
Side note: sourcing someone else's shell script means executing code that he's written. In other words, you're giving your friends access to your account whenever they want.
Side note: .bashrc
is not the right place to set $PATH
or any other environment variable. Environment variables should be set in ~/.profile
. See Which setup files should be used for setting up environment variables with bash?, Difference between .bashrc and .bash_profile.
Check /etc/default/login
for login shells. You can force an initial path there.
Adding your variables to /etc/profile should work, depending on the version of Solaris running. A more portable, for Solaris, way of doing it would be to separate setting the PATH variable and exporting it.
JAVA_HOME=/usr/jdk/instances/jdk1.7.0
GROOVY_HOME=/usr/local/bin/groovy-2.1.3
PATH=${PATH}:${GROOVY_HOME}/bin:${JAVA_HOME}/bin
export PATH
Solaris 11, where bash
is the default shell will work ok with your profile, but older Solaris version may not parse the export PATH=...
syntax as expected, or at all.
Also, keep in mind that you're only changing the initial PATH for users. /etc/profile
is read before a user's .profile
is read.
By default, Solaris users will usually end up with their own .profile
file that contains a default PATH.
solaris:~$ grep PATH .*
.profile:export PATH=/usr/bin:/usr/sbin
Since this .profile is being read in after the /etc/profile
that you've modified, your changes to $PATH
will be discarded and the user's entries will take over.
You can add these changes for new users by editing the file /etc/skel/.profile
, but to make the changes permanent for existing users, you would need to edit their individual .profiles, or overwrite them if they haven't edited them themselves.
Best Answer
If on Linux, I suppose your
csh
istcsh
. Then you should be able to do:In
csh
,tcsh
andzsh
, the$path
special array variable is tied to the$PATH
scalar environment variable in that the elements of the$path
array are constructed by splitting the$PATH
variable on the colon character. Any modification of either$path
or$PATH
is automatically reflected into the other variable.-f
above is to retain only the first entry.$path:q
is the elements of$path
, quoted, that is preventing word splitting. So the syntax above prepends the/new/entry
or moves it to the front if it was already there.Why would you be using
csh
though?Note: the quotes above are necessary. Or more precisely, all the characters in
/new/entry
need to be quoted one way or another.is OK.
is not. You can always do it in two stages though:
(one of the reasons you may want to stay away from
csh
)