ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
umm.. if you're $PATH is setup propperly, you could do it quite easily in shell-scirpt....
Code:
#!/usr/bin/ksh
INPUT=$1
cat ${INPUT} | while read app
do
which ${app} >/dev/null 2>&1
[[ $? -eq 0 ]] && {
echo "${app} is a linux command!"
continue
}
echo "${app} is not a linux command!"
done
So, if you saved the above code in a file called "check.sh" and you had a file with commands (one per line) called commands.txt you would run:
If you must do this in awk, then the system() call might help. It would be easiest to invoke something like the scripts already shown, but if you have to make the call in-line, then something like this should work:
system("IFS=:; for dir in $PATH; do if test -x $dir/"$1"; then exit 0; fi; done; exit 1")
or just
system("which "$1)
That returns 0 if $1 is on $PATH and executable, or 1 otherwise. Only tested on HP-UX, but it should work anywhere :-)
Last edited by Nick_Battle; 02-07-2007 at 07:39 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.