is there a way to run my perl scripts from any location?

Hello, I have a bunch of perl scripts located in /Users/richsark/scripts


Is there a way I can excute a perl file or even a .sh file from whereve directory I am in?


so if I am in /Users/richsark/anywhere/file/location


I can put in a few letters of my perl script name then hit tab to auto-complete the rest and run it?


Thanks

Posted on Aug 28, 2012 6:36 AM

Reply
7 replies

Aug 28, 2012 7:00 AM in response to etresoft

Hi there. Yes they are all excutable


You mentioned put "." in my path .... I think I need that... do I vi /etc/profile?


if so I have this..


PATH="$PATH:/opt/local/bin:/opt/local/sbin:/Users/richsark_air/scripts"

PERL_LWP_SSL_VERIFY_HOSTNAME=0


So your saying my path line need to look like..


PATH="$PATH:/opt/local/bin:/opt/local/sbin:/Users/richsark_air/scripts/:.:

Aug 28, 2012 8:37 AM in response to richsark

Yes, and I thought that was all that was needed.....

I made a number of simple test cases in several different directories and that's all I needed to get it to expand and run a script.

steve ~ >Hello.pl

Hello World!


steve ~ >example4-1.pl

ACGGGAGGACGGGAAAATTACTACGGCATTAGC

When it expands it include the '.pl' without that it doesn't run.


But some examples I tries, expands but not the .pl, and I get an error when i add the extension

steve ~ >drawrna.pl

-bash: /Users/steve/Mac Programming/Genomic Perl/appa/drawrna.pl: /usr/bin/perl^M: bad interpreter: No such file or directory

These are are sample code for texts and I suspect part of the problem may be the "how do you terminate a text line" issues.


But for the moment it I'm a bit puzzled


What are you seeing when you try it.


Does it expand at all?

If so what happens when you try and run it?

Aug 28, 2012 9:33 AM in response to richsark

richsark wrote:


Hello, I have a bunch of perl scripts located in /Users/richsark/scripts


Is there a way I can excute a perl file or even a .sh file from whereve directory I am in?


so if I am in /Users/richsark/anywhere/file/location


I can put in a few letters of my perl script name then hit tab to auto-complete the rest and run it?


Thanks


Ok. To summarize.


Your PATH must contain both the location of your scripts, and the notion of current working directory (.)


My perl scripts start with a line like this:


#!/usr/bin/env perl


That way, if you investigate perlbrew in google, you will appreciate this syntax.


I put everything in my .bashrc file and the only thing in my .bash_profile is a check for .bashrc as shown below. I do not use a .profile.


.bashrc

# let me execute anything from my current working directory, or designated scripts directory

# additional necessary paths as needed. You may use ~ instead of $HOME.


export PATH=.:$HOME/scripts:$PATH


.bash_profile


# if file exists and > 0

[[ -s $HOME/.bashrc ]] && source $HOME/.bashrc


$ source .bashrc

$ chmod +x myscript.pl myscript.sh

$ cd ~/Downloads

$ ./myscript.pl

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

is there a way to run my perl scripts from any location?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.