help using terminal

Joined
Oct 26, 2010
Messages
1
Reaction score
0
Points
1
I'm taking a survey course of languages and we are covering perl this week. I have never used terminal before. I need to write perl script that will parse xml data, but I can't even figure out how to use the terminal.
when I open the terminal I get this line(I subed out my name and username):

firstName-LastName-MacBook-Pro:~ username$

i have tried the commands ls and that works, but I can't figure out how to run scripts from a file. I have tried a simple hello world app by typing:

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

in text edit saving it as hello.pl then I tried to type hello.pl in the terminal and it says
-bash: first.pl: command not found

can someone explain in simple terms how to run simple programs like this?

thanks, aaron
 
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
Find yourself a website on using the Bash shell and shell scripting. Here are a couple to get started:
LinuxCommand.org: Learn the Linux command line. Write shell scripts.
Bash Prompt HOWTO

Also make sure you're saving the files as plain text if you're using TextEdit. You might want to consider using Nano in Terminal instead.
To run the script, make sure the file is excutable (chmod +x filename) and preface the filename with a ./ to run it. This will tell the shell the file is in the current directory.
 
Joined
Feb 26, 2010
Messages
2,116
Reaction score
123
Points
63
Location
Rocky Mountain High, Colorado
Your Mac's Specs
1.8 GHz i7 MBA 11" OSX 10.8.2
First you have to figure out where perl is -
Code:
which perl

Make sure that matches what you put in the #! line - mine is actual in /opt/local/bin

If you want to run the script you have to set it to executable
Code:
chmod 755 first.pl

Then you can do
Code:
./first.pl
Which should run.

Here is a little more info on permissions
Linux and UNIX chmod command help
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top