LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-13-2011, 01:42 PM   #1
hotspur919
LQ Newbie
 
Registered: Jan 2011
Location: Glasgow, UK
Distribution: RHEL, mint
Posts: 25

Rep: Reputation: 0
Python, Perl or Shell scripting?


Hi,

I'm just after some advice please.

Ive been meaning to start to put some serious effort into learning shell scripting but (being able to write only very basic scripts at the moment): A few people have said that if I want to learn scripting then I should just learn Python as its a bit more intuitive and "the way forward" as they put it.

In your opinion is this the case? Any advice would be appreciated

Cheers
 
Old 06-13-2011, 01:46 PM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296Reputation: 1296
Hello,

I've only used shell scripting in the past to automate things and it was the only thing I knew. Some time ago I started learning Perl but because of workload couldn't dedicate very much time to it. Recently I started learning Python and I can only say that's it's very intuitive once you get the hang of it. Furthermore it's very powerful, easy to learn, structured, and a lot more advantages. So yes, go for Python is what I would say but don't loose your roots to shell scripting. You might encounter yourself in a situation where shell is all you have without the possibility to install / use Python.

Kind regards,

Eric
 
1 members found this post helpful.
Old 06-13-2011, 01:56 PM   #3
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
There's no one scripting tool that will solve all your problems. Python might be great to know, but shell scripting is always available. I wouldn't argue for learning only one or the other.

Once you know one scripting language, it's easy to apply the same concepts to the next. Computers are computers are computers... they all do the same things in pretty much the same ways. The only big changes are in tool sets and syntax.

Real-world problems are always the best teachers. I would identify some particular things you're looking to script right now, and see if one scripting language is better for the task than another. Then just run with that scripting language for a while until you feel comfortable with it.
 
1 members found this post helpful.
Old 06-13-2011, 02:13 PM   #4
hotspur919
LQ Newbie
 
Registered: Jan 2011
Location: Glasgow, UK
Distribution: RHEL, mint
Posts: 25

Original Poster
Rep: Reputation: 0
Hi EricTRA, SL00b,

Thanks for your advice!

I think I will give Python a blast, but as you have both said Ill try keep my hand in with good old shell scripting also.

best regards

Jim
 
Old 06-13-2011, 02:22 PM   #5
mk27
Member
 
Registered: Sep 2008
Distribution: fedora, gentoo, ubuntu
Posts: 148

Rep: Reputation: 23
Bash (shell) scripting is a lot more limited and awkward to use in terms of syntax. IMO, it comes in handy when what you mostly want to do is "batch process" a bunch of system commands, in which case it is less awkward than using an interpreter such as perl or python. For example, the init scripts in /etc/rc.d are more or less that; they are for launching/controlling system services with some flow control and reporting. These are also a good example of "when nothing else is available" because init does not load an interpreter other than the shell.

Perl has seen widespread use for longer than python, and no other language, interpreted or otherwise, has as extensive a system of installable modules. I think most other interpreted languages have followed perl in this and many other ways, which is to say, perl led the way (and arguably continues to do so, but only time will tell). That doesn't make it by definition better of course, just more mature

I think you will have more fun with perl or python than bash. Ruby is also a very easy to learn, full featured language. It might actually be better for a first language than either perl or python, because it is less idiosyncratic. Eg, python's use of whitespace, or perl's OOP, are highly idiosyncratic, and do not mesh well with normative conceptions of how a language should work. But ruby has a very generic, straightforward feel. On the other hand, ruby has fewer modules etc than either perl or python, meaning you have fewer choices about how to do things.
 
1 members found this post helpful.
Old 06-13-2011, 02:32 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 9,985

Rep: Reputation: 4569Reputation: 4569Reputation: 4569Reputation: 4569Reputation: 4569Reputation: 4569Reputation: 4569Reputation: 4569Reputation: 4569Reputation: 4569Reputation: 4569
We need more information, namely on the kinds of scripts you want to write. Python and BASH are not used for the same things.
 
1 members found this post helpful.
Old 06-13-2011, 04:58 PM   #7
j1alu
Member
 
Registered: Apr 2009
Distribution: debian gnu/linux
Posts: 798

Rep: Reputation: Disabled
Might be you enjoy this video:
http://confreaks.net/videos/363

As far its me, without much talent for programming, the advantage of bash is that you can start quite soon to do useful things
(the main reason, as far i can tell, is described in the video).
 
1 members found this post helpful.
Old 06-13-2011, 11:49 PM   #8
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Use both. Text processing (and a lot of other things) are more easy can be done in Python, but for running external programs shell scripting more suitable/easy (IMHO)
 
1 members found this post helpful.
Old 06-14-2011, 06:18 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
In my opinion, shell-scripting was never really intended to be the quasi-programming language that it has become. "That is what 'shebang' (#!) is for."

On any typical Linux system, you have many professional-grade scripting languages at your fingertips (and I have professionally used them all):
  • Perl
  • Python
  • PHP
  • Ruby
  • (many more)
... as well as powerful command-line tools such as awk.

There is no "one language to rule them all," and perhaps this is the real point. Each of them, by design, far exceeds the (designed...) capabilities of bash, which of course is no slouch, either. All of them are free and ready for your forthcoming learning experience.

You would do very well to, as I have done, make it part of your daily business to "learn about another language." Programming languages are the most fundamental tools of your craft.

Last edited by sundialsvcs; 06-14-2011 at 06:19 AM.
 
1 members found this post helpful.
Old 06-14-2011, 09:49 AM   #10
onebuck
Moderator
 
Registered: Jan 2005
Location: Summer Midwest USA, Central Illinois, Winter Central Florida
Distribution: SlackwareŽ
Posts: 13,654
Blog Entries: 36

Rep: Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844Reputation: 2844
Hi,

'Elementary my dear ...', scripting is used basically to have a task that is functional. Most shops will utilize scripting (bash for example) to perform set tasks. If successful then sometimes will remain at that level of programming. If time is a restraint or efficiency then a different level of programming will be used based on the script model. Good example is system configuration scripts or performance scripts. Editable therefore modifiable for a users needs. Whereas some executable/complied programs require more steps to modify to suit a user's needs.

It all depends on the demands or description of the task(s). My suggestion would be to become efficient in bash or similar then move to another programming level to enhance your abilities.
HTH!
 
1 members found this post helpful.
Old 06-14-2011, 11:02 AM   #11
hotspur919
LQ Newbie
 
Registered: Jan 2011
Location: Glasgow, UK
Distribution: RHEL, mint
Posts: 25

Original Poster
Rep: Reputation: 0
Talking

Hi all,

Thanks for all your comments and suggestions. I mainly wish to write scipts to aid and guide the user in reasonably basic numerical problems specific to work related tasks. But I also would like to write scipts to complete mundane tasks like looking for specific files, tarring them up and scp'ing files and logged data across the network.

I think both Shell scripting and Python is what I might go with, but I certainly wouldnt rule out any other options. Maybe I was looking for an "easy option" as Shell scripting seems to be a bit of a pain sometimes.....I suppose practice is the key.

Again thanks for your response.

This linux community thingy is great init!

Cheers

Last edited by hotspur919; 06-14-2011 at 11:09 AM.
 
Old 06-14-2011, 01:28 PM   #12
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
Then here is my three-fold suggestion:

(1) It is a waste of time, IMHO, to try to get "bash" to do sophisticated programming tasks of any sort ... even though it has been done. In my opinion, "the designer's intent," when he or she was creating the scripting capabilities of bash, was not "to create a programming language." (Note: in the case of the Korn Shell, ksh, it most definitely was, but I do not agree with Dr. Korn that this is an appropriate or necessary place for a programming language to be.

(2) Make a moderately serious effort to learn something about all of the languages I mentioned above. All of them have websites. Pay particular attention to the libraries of contributed code that exist for all of them. (I cordially invite you to pay especial attention to the CPAN library of Perl, although in doing so I express my own personal bias ... and, "everybody's got one, so there." )

(3) You will quite naturally find yourself using one of the languages on an ever-more frequent basis. Since all of them are "at your beck and call, entirely free of charge," well ... let me warn you ... you just might find that "experimenting with another programming language or tool" is positively addictive. (Not to mention "pure gold" for your career!)

-----

I personally find it extremely engaging ... fascinating ... to see what the designers of programming languages and tools are constantly coming up with. I keep stumbling into them. (Including, most recently, a fascinating statistics package called R, which is absolutely stunning, and the GNU Prolog language, which can solve intractable logic-problems or Sudoku problems in seconds.) It's something that I have been addicted to for ... ahem ... more than thirty years now. And it's all there, and it's all free, on your friendly neighborhood Linux system.

Uh huh. I guess I am just like those people who, "if you don't know what to give 'em for Christmas, you give 'em a new tool." 'Cept all the tools I'm talking about are free.

Last edited by sundialsvcs; 06-14-2011 at 01:30 PM.
 
1 members found this post helpful.
Old 06-16-2011, 11:39 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,847

Rep: Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584
If you're working on Linux, you need to know at least one shell (default bash), as that's the lang you'll be using at the cmd line anyway.

For longer/more complex scripts/programs, I definitely recommend Perl as with sundialsvcs.
As well as CPAN, another thing to note (performance speed) is that shell scripts are interpreted, whereas Perl is 'compiled' on the fly (http://www.perl.com/doc/FMTEYEWTK/comp-vs-interp.html), then the result is run; much quicker than bash.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
PYTHON or Bash Shell Scripting? latinmusic74 Linux - Newbie 4 06-04-2010 10:58 AM
Perl or Shell Scripting latinmusic74 Linux - General 7 10-24-2009 03:01 PM
LXer: Eclipse DLTK IDE for Perl, Python, and PHP scripting LXer Syndicated Linux News 0 02-08-2009 02:22 AM
Shell Scripting/Python/C MCD_Thom Linux - Newbie 4 11-09-2004 11:40 AM
Python and shell scripting nixdisciple Programming 3 06-07-2002 07:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration