Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

where should the awk program command file be placed when I am trying to run the awk command inside a shell script? I guess it should be in the same directory, but not sure. Please help.

share|improve this question

If you are trying to run an awk command from a shell script, then the awk command has to be inside the PATH used by the script file. The easiest way to ensure that this is the case (and also to ensure that the script doesn't erroneously pick up things in the users environment is to set the PATh at the top of the script file yourself). e.g:


generally awk will be installed at the system level into one of those. If awk is merely in the same directory as the script, then it won't be picked up unless either that directory is in the path, or "." is in the PATH and you are running the script from the directory in which it is in.

share|improve this answer
Hard-coding a path in a shell script can lead to problems where other "bin" and "sbin" directories may be ignored. For example, on NetBSD where the packages system (pkgsrc) is used, the path you suggest doesn't include the /usr/pkg/bin/ or /usr/pkg/sbin/ directories. – Randolf Richardson Mar 3 '11 at 10:50
Well - in that case you'd have to hard code appropriately. Relying on the user set PATH is worse - you have no guarentee that it is correct, and additionally you open a hole that malicious software installed somewhere non standard on the system could use. The script has to include it's own dependancies, otherwise the user experience is unpredictable. – cbz Mar 3 '11 at 11:07

If it is in the current working directory, then use "./awk" instead of "awk" for the command. Normally on Unix/Linux it will be in the path.

share|improve this answer

You must log in to answer this question.

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