Get back to work!

Web Engineering Unix FAQ: Command not found

Command not found

You've created a perl program -- let's say it's called myprog.pl. You've made it executable, using chmod a+x myprog.pl, and verified that it's OK by typing ls -l myprog.pl So far, so good. Then you type its name, as in:

myprog.pl

Instead of running correctly, you see a message something like:

myprog.pl: Command not found.

You curse! You swear! It worked perfectly when you ran it by explicitly invoking the Perl interpreter (as in "perl myprog.pl"), but now it doesn't. How can it not be found -- it's there, and its permissions are OK. It should work. In fact, there are three possible reasons (that I can think of) for its failure. They are:

  1. You don't have the current directory, "." in your path. You can tell if this is the case by giving the Unix pathname to your Perl program by either of the following tricks:
    ./myprog.pl                       # relative, or
    /usr/home/student/psc/myprog.pl   # full Unix path
    
    If either of these works (and note that the full path option must be the real full path to your Perl program) then you need to check the PATH FAQ entry for more information on how to get "dot-in-your-path".
  2. If the previous tricks don't work, you've almost certainly stuffed up the "hashbang" (#!) line in your Perl program. In this case, it's not your program that's "Command not found", it's the Perl interpreter itself -- the hashbang line is supposed to give the full Unix path to where it's located in the filesystem. Copy the pathname (something like "/usr/bin/perl") from the hashbang line of your program, and do an ls -l on it in a shell window. It should exist and be executable. You can also use the command which perl to show you where the Perl interpreter really lives on your system.
  3. The last possibility, and also related to the "hashbang" line, is that you've created the Perl file on a M$ Windoze box and transferred it to the Unix server without doing a textfile translation. In this case you've got a text file with DOS line endings on Unix. What's happening is that the system is looking for an interpreter named (for example) /usr/bin/perl\r, which it obviously isn't going to find. To solve this problem check out the DOS2Unix FAQ entry.
Copyright © 2003-2006 Phil Scott