Question

This is a pretty simple one... I just want to make a perl script executable without the preceding perl command, and instead let the environment deduce the interpreter from the shebang line. Here is my sample script called test:

#!/usr/bin/perl
print "Hey there\n";

I then use chmod 775 test to make the script executable. If I use the command perl test, I get the output Hey there.

However, if I just type test, I get no output. What's the deal? Why isn't my shebang line making the environment realize this is perl? Can someone please help me?

Was it helpful?

Solution

Don't name your script test. This is a built-in command in most shells, so they don't go looking for an external program.

Also, to run a program in your current directory, you should type ./programname. It's generally a bad idea to have . in your $PATH, which would be necessary to execute it without the directory prefix.

OTHER TIPS

To run something from the current directory you need to prefix "./" to tell it "this directory" ie ./testprogram.

If you type just test it will look in standard install directories like /bin. This is why when you run cp or rm it knows where the executable is.

As mentioned by others, naming scripts test is not allowed with most shells.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top