Shell scripting vs Perl scripting

Hi all,

I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first.
Can you please help me determine which one to really focus on as a start?

Thanks,

It depends upon your platform and long-term goals. Generally, because it is portable nearly everywhere, I would advise PERL. Longer term: BASH and/or KORN as well. There are things that PERL is not well suited to. It has greater power and is very versatile (and FAST), but anything that has to call or start other processes is better done in a shell. A mature SYSADM will be very comfortable with both shell and PERL coding.

Thanks so much! I guess I will start with perl as I have to start somewhere.

I sort of disagree...

I would start will bash, it is more basic then perl which will give you a good foundation it's much more limited then perl which will show you which things to use perl for...

Also, if you learn Perl first you will find that (as a sysadm) you will always want to do something system related, in which you run in some form a bash cmd.

With bash you generally don't have to use perl, 99.9999% of the time anyway.

But with Perl you will need bash probably 30% of the time.

agreed

STOIE is making a good point: what is the role in which you operate? It makes a difference which is recommended depending on whether you want to be a sysadmin or developer.

Yes, this is true...

What "level" do you want to dig into...?
If you wish to create CGI and things that are generally speaking not "SYSTEM" level, then maybe you will only need Perl and very basic BASH (you will always need BASH though..)

However, if you wish to dig into "SYSTEM" level stuff, which I imagine is the case being on unix.com and all, then definitely learn BASH and get that very firm before you even bother considering Perl.

Furthermore, you'll probably be using BASH or KORN to run your perl scripts, so you might as well learn to use it.

Shell scripting will allow you to quickly perform more involved commands. And, you will more naturally learn as you chain one process into the next. For instance, you probably already know the ls command, but you can combine it with other commands to get (perhaps) better info. Thus, you could ls | grep "smith" to find filenames with "smith" in them. Next, you might decide to do a loop around those results to determine whatever.
Anyway, shell scripting is simply an extension of the shell commands.

So... I would start with shell scripting.

learn them both but learn shell scripting first. I suggest sh or ksh first and then bash. This will allow you script easily on systems that don't have bash. learning Perl after will allow you to appreciate the language.

and don't forget about basic sed/awk/grep.

for system administrators i would suggest Perl because of its portability.

I would say learn both of them and when using
" use the right tool for the right job :slight_smile: "

Agreed, and Frank, you too.

find /my/dir -maxdepth 1 -type f -not -name *bz2 -exec bzip2 {} \; FTW baby!

None of this ls stuff, BASH is where the action is at.
And perl is where the trickiness is made do-able.

while (<>) {
if ($_ =~ /\S+ (\S+)\s+(\d+)/) {
print 'Index ' . $1 . ' has ' . $2 . ' functions.' . "\n";
}
}

Then mix them together:
find /my/dir -maxdepth 1 -type f -not -name *bz2 |my_perl.pl |grep -i "fancy" |awk '{ print ( $4 }' |less

Feel the powers for different tasks...

I mean lets be honest you cannot sys admin without BASH (or SH/KSH)

BASH has regular expressions these days, you know. No need to run 2 or 3 interpreters to do one job.

1 Like

Yeah I understand that, but wrote wrote something before I thought about it :frowning:

Anyway, furthers the point I guess, even BASH has the functionality to do regex.