LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2007, 06:54 PM   #1
Canadakid
LQ Newbie
 
Registered: Dec 2006
Location: Canada, obviously!
Distribution: Debian Sid
Posts: 7

Rep: Reputation: 0
Question Is shell scripting worth it?


What I mean is, compared to an interpreted programming language like Python. As far as I can tell, shell scripts are only really useful for administrative tasks, which could be done just as easily (?) in Python (or Perl, Ruby, etc.).

I want to eventually learn to program, and have my eyes on Python as a first language. Given that my interest is purely as a hobbyist, is it worth my time to learn shell scripting first?
 
Old 03-29-2007, 07:47 PM   #2
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
Shell scripting is great for quick solutions.
Grep, sed, and awk are your friends.

I have performed so many things just by a simple shell script.

Shell scripting is easy to learn.

Also in conjunction with learning shell scripting you learn about Regular Expressions ... which is essential if you are dealing with other scripting such as Perl.

I have decided to learn shell scripting before I move on to Perl.
 
Old 03-29-2007, 07:50 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
An interpreted language is generally kept on /usr, however your shells authorized for script execution are generally kept on /. This means that interpreted languages aren't always available during initial startup, so if you want something done at startup you should use a shell script.

Shell scripts are great for things that you would normally have to hand jam into a console each time you start your system. I use scripts to set up my system at startup, to include things like automatically detecting a USB drive so that it can mount encrypted file systems automatically, otherwise do "something else". I also use a script as a wireless LAN monitor so that if the link goes down then it will automatically reset it and bring it back up. All of these things I could do in an SU terminal, however it would be the same actions every time so I choose to make them scripts.

The bottom line is that if you know what you need to do in a terminal there is no sense trying to translate it into something besides what the terminal itself interprets.
ta0kira
 
Old 03-29-2007, 08:40 PM   #4
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Shell scripts support pipelines, the scripting-language analog of which (functional composition) is usually less-well supported (by the language). The flow of text as it is filtered and translated from one program to another is one thing that Unix shell scripting has always been very good at.

Shells are also much more lightweight than, say, a full-blown Perl interpreter.

Just a few reasons why shell scripting still matters. Not to say that I couldn't rewrite all my shell scripts in Perl or Python or Java or C, but I wouldn't want to. Neither would I want to rewrite my kernel in Ada, even though I could.
 
Old 03-29-2007, 08:47 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You also need to know how to shell script if you ever want to edit the startup scripts (rc.*) provided by your distro. Some people actually see that as strange, but on most systems it's required at some point. Better than having to come to LQ if you run into the smallest problems. That can take days, whereas knowing how a script works can ease the majority of your problems.
ta0kira

PS I think it's a fundamental *nix skill that should never be overlooked or dismissed!
 
Old 03-29-2007, 08:54 PM   #6
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 48
Quote:
Originally Posted by Canadakid
What I mean is, compared to an interpreted programming language like Python. As far as I can tell, shell scripts are only really useful for administrative tasks, which could be done just as easily (?) in Python (or Perl, Ruby, etc.).

I want to eventually learn to program, and have my eyes on Python as a first language. Given that my interest is purely as a hobbyist, is it worth my time to learn shell scripting first?
The shell as a command line and the shell as a programming language is an artificial distinction. Knowing how to use the shell to launch programs, list files, pipe input from one program to input of another on the command line gives you all you need to write a simple shell script. This is a concept that most MS-DOS users can grasp when they write their first .bat file. However, MS-DOS has nothing to offer as a programming language, therefore this is a one way street.

The Unix shell, particularly Bourne Shell derivatives are different. Shell functions, for and while loops, if and case clauses and shell variables are all powerful tools at the command line.
 
Old 03-30-2007, 03:20 AM   #7
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
I believe I'll go back to running DOS if I ever see that /bin/sh is a link to Python or Perl...
If Python was the main shell for Linux, it would take a *long* time to boot.
 
Old 03-30-2007, 04:01 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I think so, I get paid a nice living for it
 
Old 03-30-2007, 04:47 AM   #9
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Canadakid
What I mean is, compared to an interpreted programming language like Python. As far as I can tell, shell scripts are only really useful for administrative tasks, which could be done just as easily (?) in Python (or Perl, Ruby, etc.).

I want to eventually learn to program, and have my eyes on Python as a first language. Given that my interest is purely as a hobbyist, is it worth my time to learn shell scripting first?
Learn shell/Perl for simple administrative tasks and whose code doesn't go beyond what you can read and comprehend. Learn Python for doing more complex jobs, like text manipulations, formatting reports , socket programming, GUI programming and many more etc etc. Also, Python codes tend to be easy to read, understand and maintain.
Regular expressions are good, as some people said, but too much of it becomes unyieldy, hard to understand and difficult to troubleshoot for bugs, especially for a noob sysadmin. these are just my $0.02
 
Old 03-30-2007, 05:07 AM   #10
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
if you are seriously going to do stuff on a linux/unix box
you cannot escape shell scripting.


it's all part of the tool box.
 
Old 03-30-2007, 06:47 AM   #11
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 735

Rep: Reputation: 76
Hi, Canadakid.
Quote:
"Why should you learn shell programming? Because often, medium-sized to large problems can be decomposed into smaller pieces, each of which is amenable to being solved with one of the Unix tools. A shell script, when done well, can often solve a problem in a mere fraction of the time it would take to solve the same problem using a conventional language such as C or C++. It is also possible to make shell scripts portable -- i.e. usable across a range of Unix and POSIX-compliant systems, with little or no modification."

Classic Shell Programming, Robbins & Beebe, O'Reilly, 2005
Best wishes on embarking on a new adventure ... cheers, makyo
 
Old 03-30-2007, 06:49 AM   #12
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
I'm a big fan of Python, but sometimes bash is just quicker and easier.
 
Old 03-30-2007, 06:58 AM   #13
omnio
Member
 
Registered: Feb 2007
Location: $HOME
Distribution: Hardened Gentoo
Posts: 66
Blog Entries: 1

Rep: Reputation: 16
Yep. And everyone has already a shell installed on his/her system.
 
Old 03-30-2007, 08:15 AM   #14
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
You might also ask, "Is Python really worth it, when I can re-write python programs in C?". The answer to both your question and this one is "yes". The reason is that some tasks are simply better suited to some languages.

Why write 20 lines of C when you can do a one-liner in perl or python? Maybe it's faster in C, but maybe the performance isn't worth the time spent in writing and debugging. Similarly, there will be tasks which are more easily accomplished using shell scripting.

There is no "one language to rule them all". Learn many languages, and choose the best suited to a given task. Be sensible of course - too much mixing can lead to a chaotic solution. The thing to do is learn about many, and then use your experience to judge what is a good solution to a problem.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
Shell Scripting Help Elguapo Programming 1 09-07-2006 07:03 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
Is scripting worth learning ChimpFace9000 Linux - General 3 07-05-2001 04:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:56 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