Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top