Wc / Cat Command Not Found

Wc / Cat Command Not Found

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. Besides,

machine:~ user$ which wc
/usr/bin/wc

and

machine:~ user$ which cat
/bin/cat
2

1 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 =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.