Solved

Cannot execute a Perl Script from the command line

Posted on 2004-10-20
3
1,004 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
  • 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 50 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now