?
Solved

Cannot execute a Perl Script from the command line

Posted on 2004-10-20
3
Medium Priority
?
1,012 Views
Last Modified: 2013-12-16
I wan't to execute a perl script from the command line.

if I type: "perl hello.pl"

it works fine:

However if I type just: hello.pl

nothing happens I just get "bash: hello.pl: command not found"

How do I get around this, I assume I have to edit my PATH or something to point to my perl executable!!!

Any help....
- Troyh
0
Comment
Question by:Troyh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:de2Zotjes
ID: 12361197
try doing:
cd to teh directory where hello.pl is stored.
chmod a+x hello.pl

This command "tags" the file hello.pl as an executable.

If the file allready is executable then again cd to the directory where hello.pl is stored and do ./hello.pl

If that last one works it means that you stored hello.pl in a directory that is not in the path. There are 2 solutions to that problem:
1) move the file to a directory that is in the path. This would be my choice, the custom for "home" made stuff is to put it either in  /<userhome>/bin or /usr/local/bin
2) add the directory where hello.pl is stored to the path. How to do this depends on the shell you are using.
0
 

Author Comment

by:Troyh
ID: 12362121
It works fine if I put the script into the /usr/local/bin

I am using the /usr/bash SHELL, so how do I update the PATH for this shell?

- Troyh
0
 
LVL 6

Accepted Solution

by:
de2Zotjes earned 150 total points
ID: 12362284
You do not need to now, since the script is in the path by moving it, but..

for bash:
simple update of running environment:

export PATH=$PATH:/the/new/path/element

making this permanent for a single user:
edit the file /<userhome>/.bash_profile
add the export PATH=... line as the last line of the script

making this permanent for all users:
edit the file /etc/profile
I can't give any exact directions, because different disto's have different ideas of what this profile looks like, so updating it is distro dependent.
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question