Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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:

PATH=/usr/bin:/bin:/usr/local/bin

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
1  
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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.