Question:
In Unix programming, what is better: bash shell scripting or using perl?
Mk
2008-07-04 20:29:07 UTC
Im just starting to learn Unix and Im already familiar with C programming.
Seven answers:
jeo
2008-07-07 05:34:02 UTC
refer these links



http://www.linuxforums.org/forum/linux-programming-scripting/32718-perl-python-vs-bash.html

http://www.daniweb.com/forums/thread46340.html

http://www.perlmonks.org/?node_id=661859

http://www.linuxquestions.org/questions/programming-9/perl-vs.-bash-code-number-of-lines-534142/
TK "Snobol" Erlang
2008-07-05 11:04:31 UTC
They're both good ...



I wrote a small system several years back at work. I started writing all the scripts in bash initially. If I found that the task became too difficult for bash, I'd switch to perl. By the end, most of my scripts were written in bash, with the rest being written in Perl.



So ... it's quicker to write scripts in bash if the complexity of the task is low to medium. Once the complexity of the task exceeds mid-level, then you're going to be better off using Perl.
rlfwolf
2008-07-07 10:07:23 UTC
I've done lots of scripting using sh/bash, perl, and tcl. In many cases, the choice of what language to use was made for me due to either company or group standards or due to integration with an existing tool/library set. I find myself using sh/bash most of the time due to it's ease of porting between unix/linux systems and because it's simply easier to do small tasks. I've written bourne shell scripts that's just a single line and whole tool sets that included 5-10 different scripts. In the end, the choice usually depends on what I need to do. Here's what I feel each has to offer:



Shell scripting (sh/bash)

+ Simple to write small scripts.

+ If written correctly, will run on almost any unix/linux system.

+ Best choice when there are lots of interaction with other commands.

- Not as easy to learn if you already know C for instance.

- sed/awk are very powerful tools but not as easy to use as perl when it comes to text processing.



Perl

+ Moderate to high extensibility. Meaning you can write or install additional libraries to add functionality.

+ Highly efficient for processing files. Only language I know that contains special syntax to open and read all lines in a file into a loop variable.

+ Text processing (RegEx) built-in

+ Best choice if you need to do a lot of text processing. Very powerful regular expression language (extended from what you have in sed)

- More overhead.

- Library dependencies can kill your portability.

- Some systems like busybox based systems just don't have perl.

- A bit top heavy for a script language. Meaning too many special commands.



TCL

+ Highly extensible. Even early versions had namespace and module capabilities.

+ Very efficient language overall. Very few wasted commands/keywords.

+ Built-in associative arrays. In fact, all arrays are associative.

+ Able to develop portable gui using "wish".

+ Tcl has many spin-off languages like "expect".

+ Best choice if you have lots of "logic" in your script. Only choice if you want to write a simple gui interface in a script.

- A bit harder to learn than Perl but arguably more powerful.

- Not as widely used as Perl.

- String manipulation (i.e. RegEx processing) is done through a function call rather than a built-in as in Perl.



If you already know C, start with Perl. That'll be the easiest for you to learn. I'd then suggest you move to bourne shell. Here, I'll make the distinction between "sh" and "bash". If you learn "sh", that will be the most portable but "bash" is pretty much used in all modern unix/linux distros so it should not be a problem.
petdance
2008-07-04 20:35:08 UTC
Depends on the task. If it's anything more than simply running different other programs in sequence, Perl is probably the way to go. The Perl program will also be portable elsewhere if you ever decide to run on Windows.
martinthurn
2008-07-05 10:41:15 UTC
If you already know C, then Perl will be EASY to learn. I've been programming Perl for over 10 years and I still have "issues" with shell languages 8-)
2008-07-04 21:19:34 UTC
bash shell command files run on any unix system without installing anything else. a perl install is extra work and sometimes you can't install it on machines you work on.



If it is a simple task bash command files will be fine. and it is useful, even if you do a lot of perl.
2014-11-05 21:43:14 UTC
perl is much powerful for complicate script


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...