LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question regarding the $PATH utility (https://www.linuxquestions.org/questions/linux-newbie-8/question-regarding-the-%24path-utility-943891/)

hemel1987 05-08-2012 08:55 AM

Question regarding the $PATH utility
 
Hello all,
I am using VMWare Workstation 7 and have installed a NEW COPY of RHEL Enterprise Edition 6.0 in it.
After i enter the bash shell as the SuperUser, and type the command:
echo $PATH and then press Enter
I am only able to see the following paths, namely:
1. /usr/kerberos/sbin; 2. /usr/kerberos/bin; 3. /usr/local/bin; 4. /usr/bin; 5. /bin; 6. /usr/X11R6/bin; 7. /home/user/bin
However, ideally there should be, in addition to the above, paths like: 8. /sbin; 9. /usr/sbin; 10. /home/user/sbin.

This problem seems to occur intermittently, so here are a few things that occur to me:
a. Since this is a fresh copy, and i haven't removed anything yet, i assume either its a problem with VMWare or my RHEL installation is corrupted?
b. Else as suggested by a friend, i may be able to use the export command to add the above paths. Incase this is possible, can someone also provide me with the syntax as to how the export command can be used for this scenario?
c. If there is any other scenario, i am overlooking with regards to this, please let me know?

Thanks for any help you can provide..

Regards,
hemel1987

acid_kewpie 05-08-2012 08:58 AM

$10 says you are becoming root by running "su". This does not create a full root environment (SuperUser? What's that...??). either run "sudo -i" or "su -" to get a proper root login shell.

How on earth this could possibly be a VMware is way way beyond me!

hemel1987 05-08-2012 09:21 AM

Hi,
Thanks for the info.

Using the 'su -' does provide an additional set of paths once i execute the echo command. As you mentioned, i overlooked the differences of 'su' and 'su -'.

I have another question regarding whether the 'export' command can be used to define additional paths as i had mentioned before?

Grateful to anyone who can provide me a syntax for the same..

Regards,
hemel1987

P.S. SuperUser was the alias that i had used for the root user. Some people here prefer to call it that. (http://static.linuxquestions.org/que...s_lq/icon7.gif)

acid_kewpie 05-08-2012 09:24 AM

you can use export yes, but not in the way I expect you think it will work. You would generally add those commands to your ~/.bash_profile but be careful what you add, generally you really wouldn't need to change it, and if you think you do, you're doing it wrong. for example, your current directory should never be on your path. Other times sure you do need to. The script here, or system wide at /etc/profile, are where those paths are set, so you can see the current export commands in them directly.

I don't think anything **here** would prefer "SuperUser" over "root" :)

wpeckham 05-08-2012 12:23 PM

well
 
I think you are in for a lot of reading, and a lot of fun.

The earlier comments apply, I have no argument with anything said so far.
I do want to add one thing: $PATH is an environment variable, not a function or utility. The difference may be critical.
It does not accumulate: ie a second assignment REPLACES the first.

For example the following sequence
Code:

PATH=/bin;/usr/bin:/usr/local/bin
PATH=/sbin;/usr/sbin:/usr/local/sbin
echo $PATH

would generate output something like
Quote:

/sbin;/usr/sbin:/usr/local/sbin
There are some script and program utilities that allow you to pass a parameter, and (assuming it is a folder) they will check the current PATH and optionally add or remove it from the path as needed. (Testing to ensure that no path is added twice, etc.)
I know of no one who uses them extensively for anything other than startup scripts and automation. (pathmung come to mind)

An effect something LIKE those functions is easy to provide using a technique like this:
Code:

PATH=/bin;/usr/bin:/usr/local/bin
PATH=${PATH}:/sbin;/usr/sbin:/usr/local/sbin
PATH=${PATH}:~/bin
echo $PATH

might result in output that looks like
Quote:

/bin;/usr/bin:/usr/local/bin:/sbin;/usr/sbin:/usr/local/sbin:/root/bin
I hope this helps.


All times are GMT -5. The time now is 11:17 AM.