-1

I am running Manjaro Linux and perl 5.20.1, which came pre-installed.

I have started learning perl and need to get it in my path in ~/.bashrc. (Manjaro uses .bashrc and not .bash_profile). I should be able to run my scripts from ./script.pl anywhere in my ~/. I have to now go to the directory where they are, make executable then type perl myscript.pl.

Can't I add a $PATH and be able to just run from ./myscript.pl?

2

I think that the answer you are looking for is point 3, but just in case I have added points 1 and 2:

  1. If you run

    perl script.pl
    

    then you do not need to make the file executable. If a file is not executable then you pass the name of the script, as an argument, to the perl command.

  2. If you can run perl without specifying a path (i.e. /usr/bin/perl script.pl), then the perl executable is already in your path env (because you are not specifying a path).

  3. If you want to run the script without specifying the command perl explicitly, then you don't need to add anything to your PATH env, you instead specify the path in the script. So, in addition to making the script executable (which you have already done), put this as the first line of the script

    #!/usr/local/bin/perl -w
    

    Change the path in the script accordingly to specify the correct path. which perl will tell you the path to your perl executable.

So, for example:

#!/usr/local/bin/perl
print "Hello World!\n";

Now, you can run it with ./script.pl

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.