ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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
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.
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!
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.
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.
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
"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."
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.