1

Just wanted to know - is there a standard path where uname is installed? e.g. /usr/bin/uname or /bin/uname

I'm asking with regards to HP-UX, AIX, SunOS and RedHat Linux

Is there a common path in which all of the above contain uname? If not, how can I know on which OS my script is executing?

3 Answers 3

1

uname should be in a location that's in your $PATH which almost always includes /bin and /usr/bin. You should be able to rely on executing uname without specifying a full path.

8
  • Doesn't it matter which "copy" of uname i get?
    – RonK
    Aug 25, 2010 at 19:12
  • @RonK: Do any of your systems have uname in more than one place? The designers of some versions of Linux or Unix choose to put some utilities in different locations. Sometimes utilities appear in more than one location on the same system. If this is the case, they are often symlinked or hardlinked and so it makes no difference. Occasionally, utilities will be located in more than one place that are different versions. At least one of those will not be in either /bin or /usr/bin. If they're different and one is in each of those locations it's a mistake or bad design. Aug 25, 2010 at 19:38
  • uname is a basic utility so I don't think you should worry about it at all. Aug 25, 2010 at 19:38
  • @Dennis Williamson: What if my script is the one responsible for setting the PATH? Can I assume /bin or /usr/bin is are already in the path even for a brand new account? (I am no SysAdmin so forgive me if the question sounds stupid)
    – RonK
    Aug 25, 2010 at 20:17
  • @RonK: Try this at a command prompt: env -i bash -c 'echo $PATH'. That will show you what the default PATH is. The shell creates that value by default. If your script sets a PATH this way: PATH=$PATH:/more/dirs then the exported value will be there along with your new value. If you do it this way: PATH=/some/dir then the old value will be replaced instead of appended to. What do you mean "brand new account" - this is the first you've mentioned that. If you're talking about adding new users (or service accounts) then yes, they get a default environment... Aug 25, 2010 at 21:32
0

If you are making a general purpose script, you can include /usr/bin and /bin in the pathname if you are unsure. Then it would not matter.

0

You can never rely on binaries being in a particular location across all operating systems. Generally, for portability's sake, you will want to rely on the path being set properly. But safe programs tends to lock down the path (and Perl's taint mode modifies the path too). Thus perhaps offer the user of the script the ability to configure the binaries to be used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .