Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 28th, 2006, 3:29 PM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 837
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Bash or Perl?

Hi,

I want to learn a command line scripting language such as bash or Perl but I don't know the difference between them. Does Perl have all the same features as bash? Is Perl superior to bash, and if so, how? Which would you recommend?

Thanks for the info.

(Know of any good books in either subject?)
titaniumdecoy is offline   Reply With Quote
Old Jan 28th, 2006, 3:39 PM   #2
Nebula
Hobbyist Programmer
 
Nebula's Avatar
 
Join Date: Oct 2005
Posts: 193
Rep Power: 3 Nebula is on a distinguished road
Send a message via AIM to Nebula
I prefer Perl, but thats just me. I'm not sure about their similarities or differences.
__________________
When will Jesus bring the porkchops?
Nebula is offline   Reply With Quote
Old Jan 28th, 2006, 6:11 PM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Quote:
Originally Posted by titaniumdecoy
I want to learn a command line scripting language such as bash or Perl but I don't know the difference between them. Does Perl have all the same features as bash? Is Perl superior to bash, and if so, how? Which would you recommend?
Bash was designed for interactive use. It's much like an advanced version of the Windows command prompt. Bash is a language designed to handle running external commands, and piping their output to files, or other commands:
ls -1 > output.txt   # Write the current directory listing to a file
grep -ir toast *   # find files with the word 'toast' in
Perl, on the other hand, is much more like your classic programming language. It's not designed to be interactive, and it doesn't use external executables for its commands (at least, not often), but a number of library functions and built in commands:
print "Hello World";    # prints Hello World

# Removes the substring "cat" from STDIN and pipes it to STDOUT
while (<STDIN>) {
    s/cat//ig;
    print $_;
}
As to which one is superior - it depends on the situation. I wouldn't use Bash to write anything complex, and I wouldn't use Perl as an interactive shell.
Arevos is offline   Reply With Quote
Old Jan 30th, 2006, 8:15 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
I prefer Perl... but use bash more often for shorter scripts. Perl is a powerhouse.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jan 30th, 2006, 9:06 AM   #5
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Quote:
Originally Posted by Arevos
Bash was designed for interactive use. It's much like an advanced version of the Windows command prompt. Bash is a language designed to handle running external commands, and piping their output to files, or other commands:
ls -1 > output.txt   # Write the current directory listing to a file
grep -ir toast *   # find files with the word 'toast' in
Perl, on the other hand, is much more like your classic programming language. It's not designed to be interactive, and it doesn't use external executables for its commands (at least, not often), but a number of library functions and built in commands:
print "Hello World";    # prints Hello World

# Removes the substring "cat" from STDIN and pipes it to STDOUT
while (<STDIN>) {
    s/cat//ig;
    print $_;
}
As to which one is superior - it depends on the situation. I wouldn't use Bash to write anything complex, and I wouldn't use Perl as an interactive shell.

Heh, i have made and used non-interactive bash scripts, and i have also made interactive perl scripts. So your discription is a little off. Here's what they have posted on the bash web site:

Bash is the shell, or command language interpreter, that will appear in the GNU operating system. Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). It is intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard. It offers functional improvements over sh for both programming and interactive use. In addition, most sh scripts can be run by Bash without modification.

Perl is a scripting language, not a programming language (same with bash). Programming languages get compiled, where as languages like perl and bash get interpreted on the fly.

Perl is very powerful. you can do alot more things with perl than you can do with bash. However that being said, bash and perl both have places where they are better than the other. Bash is for quick development of scripts for doing simple yet repetative tasks on a system (ie: some kind of cron job, or moving log files around). Where perl is much more for backup scripts, clunking through logs looking for suspect entrys and generally more difficult tasks.

here's two examples of what i use bash for:

-populating a server with user accounts (30+ accounts at once), without having to enter any passwords etc...(although perl would have worked well here also.)
-re-formating the names of my mp3 collection.

and a couple examples of what i have used perl for:

-a backup script that connects to various boxes around the networks and backs up the data to a remote server (gets run by cron every day).
-an irc bot that reacts to commands givin in the chat window.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Jan 30th, 2006, 9:11 AM   #6
Dizzutch
Professional Programmer
 
Dizzutch's Avatar
 
Join Date: Dec 2004
Location: Worcester, MA
Posts: 441
Rep Power: 4 Dizzutch is on a distinguished road
Send a message via ICQ to Dizzutch Send a message via AIM to Dizzutch Send a message via MSN to Dizzutch Send a message via Yahoo to Dizzutch
i tend to keep BASH to one-liners i can run from the command line, if i am to save it to a file for cronning, i tend to use perl. Personal Preference
__________________
naked pictures of you | PFO F@H stats
Dizzutch is offline   Reply With Quote
Old Jan 30th, 2006, 10:29 AM   #7
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Quote:
Originally Posted by Pizentios
Heh, i have made and used non-interactive bash scripts, and i have also made interactive perl scripts. So your discription is a little off.
I meant, "interactive shell", rather than "interactive script". Whilst there is a Perl shell (psh), Perl is not usually used in this way.

Quote:
Originally Posted by Pizentios
Perl is a scripting language, not a programming language (same with bash). Programming languages get compiled, where as languages like perl and bash get interpreted on the fly.
Didn't DaWei recently make a post warning to be careful of providing incorrect information?

A programming language is, surprisingly enough, a language you program in. What method is used to execute the resulting code is irrelevant. C is a programming language, but so is Perl or Python. Scheme's a programming language can be compiled, or interpreted, depending on what software you use. The term "programming language" encompasses both scripting and compiled languages.

Last edited by Arevos; Jan 30th, 2006 at 10:44 AM.
Arevos is offline   Reply With Quote
Old Jan 30th, 2006, 11:27 AM   #8
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
sorry, in my world, programming language refers to a compiled language, scripting language refers to a interpreted language. Call me wrong or what ever you want, but that's how i view it. Although you are correct.

Quote:
Didn't DaWei recently make a post warning to be careful of providing incorrect information?

A programming language is, surprisingly enough, a language you program in. What method is used to execute the resulting code is irrelevant. C is a programming language, but so is Perl or Python. Scheme's a programming language can be compiled, or interpreted, depending on what software you use. The term "programming language" encompasses both scripting and compiled languages.
There's no need to be rude about it man.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Jan 30th, 2006, 1:09 PM   #9
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 4 Arevos is on a distinguished road
Quote:
Originally Posted by Pizentios
sorry, in my world, programming language refers to a compiled language, scripting language refers to a interpreted language. Call me wrong or what ever you want, but that's how i view it.
That's entirely up to you. Indeed, if you had said "In my opinion, Perl is not a programming language, because I define programming language to refer only to compiled languages", then I'd have no issue. But you presented your view as if it were the commonly accepted definition of the term, which it is not.
Quote:
Originally Posted by Pizentios
There's no need to be rude about it man.
Apologies if I caused offense, but it appeared to me that you were wrongly trying to correct me when I said that Perl was a programming language. And since there was a recent topic on the very issue of providing inaccurate information, I thought it prudent to mention it.
Arevos is offline   Reply With Quote
Old Jan 30th, 2006, 4:42 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by Arevos
Apologies if I caused offense, but it appeared to me that you were wrongly trying to correct me when I said that Perl was a programming language. And since there was a recent topic on the very issue of providing inaccurate information, I thought it prudent to mention it.
Pizentios was perfectly correct when he said "In my world, ..." - he really does live on his own, Piz-sized planet.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC