Wc / cat command not found

bashcommand lineunix

I'm trying to run some simple bash script which uses wc and cat commands. The script fails with this:

wc: command not found

or this (after I commented string which uses wc):

cat: command not found

I have no idea what's going on.
A similar script which contains exactly the same fragments of code works just perfect.
Both scripts are used in the same conditions.

machine:~ user$ which wc


machine:~ user$ which cat

Best Answer

  • As pointed out by @Tyson, the PATH variable holds the answer.

    I just wanted to point out that using full paths in your scripts is usually considered a good practice. For example, instead of calling wc you might want to call /usr/bin/wc. Besides resolving the above problem, it's more secure, as you prevent running an application that someone might have put in your PATH using the same name... I can't remember the name of those attacks, but you get the idea =)

  • Related Question