sh - find a command on $PATH -
I am writing a script, and I need to see the command at the user's $ PATH command The problem is that I do not know what the user's login shell is, or what strange stuff can be in their file, I am using Bourne Shell for my simple script because some older Solaris platforms are needed to run on That is, that can not be bash.
Some implementations of "Which" and "since" files will be the source of the user's dot, and this is not really portable for all users. I like a simple UNIX utility that is executable The original work of scanning the path and reporting the full path of the first match will be done.
But I have any / bin / sh solution which is stable for all users.
I'm looking for a solution that is better than writing a / bin / sh loop that closes $ PATH and searches for it at a time. It appears that it is a common practice to have a reusable way to do this.
"Long way" My first approximation is:
IFS =: $ I in path; If [-x $ i / $ cmd]; Then echo $ i / $ cmdf Is anyone easy and portable?
The answer seems to be 'type' built-in.
% / bin / sh $ is type ls / bin / ls
Comments
Post a Comment