Among other things, bash is useful when most of what you're doing is communicating and piping between various programs (many of which are also standard). And there are many environments where bash (or at least a POSIX shell ) is available but Perl and Python are not.
Among other things, bash is useful when most of what you're doing is communicating and piping between various programs (many of which are also standard). And there are many environments where bash (or at least a POSIX shell) is available but Perl and Python are not. And of course, you should distinguish between interactive bash and scripted bash.
Ubuntu recently switched their default scripted shell (#! /bin/sh) to dash because it was much faster. However, bash has useful interactive features dash does not (zsh is still better, IMHO).
See also Is it worth learning BASH when I know Perl?
Thank you for that linked question; very useful. – Precision May 20 '10 at 9:00 2 A little grain of salt: Python is now shipped with virtually every Linux distribution, and also with Mac OS X. As for Windows, I would guess that installing bash is less easy than installing Python… – EOL May 20 '10 at 9:06.
Bash is incredibly useful in system administration, web application deployment, data crunching, sutomated backups, even getting-things-done day by day management just to name really few of them. I think It's too early for you to judge a "veteran IT soldier" like BASH. EDIT googling around: comprehensive list of nice examples Useful bash tip and tricks 18 useful scripts for Web Devel.
Two minutes bash coding to improve your git usage I'd like also to mention that TextMate a successful OS-X program has a lot of Bash machinery inside.
I'm not "judging" Bash, I really am trying to learn what people really use it for. – Precision May 20 '10 at 8:25 Sorry for the tone I had, but what I really mean Is not that you are talking badly about Bash, but just that I don't think It's the time to judge It as "retire-ready". :) – microspino May 20 '10 at 8:47 These are things that Python can certainly do, and more conveniently than bash… – EOL May 20 '10 at 9:04 @EOL Although I agree with you and use python or ruby for a lot of tasks, there are still places where you get only bash: I think to the embedded world.
Although It is improving everyday, It's hard to find high level interpreted languages inside embedded devices and It's easy to manage them via bash or ash. – microspino May 20 '10 at 9:11 @mircospino: Interesting information about embedded devices! – EOL May 20 '107 at 12:10.
The real difference between bash and python is that python is a general purpose scripting language, while bash is simply a way to run a myriad of small (and often very fast) programs in a series. Python can do this, but it is not optimized for it. The programs (sort, find, uniq, scp) might do very complex tasks very simply, and bash allows these tasks to interoperate very simply with piping, flushing output in and out from files or devices etc.While Python can run the same programs, you will be forced to do bash scripting in the python script to accomplish the same thing, and then you are stuck with both python and bash.
Both are fine by them self, but a mix of these don't improve anything IMHO.
Bash scripts allow you to automate command line tasks by using the same language you would if you type the commands out manually. Trivial Example to list $PATH Bash #! /bin/sh echo $PATH Python print os.
Getenv("path").
So, use bash because you don't have to put environment variables in quotes...? – BlueRaja - Danny Pflughoeft May 20 '10 at 19:53 2 My point was that same language is used in scripted mode and interactive mode.(for bash) – mikek3332002 May 20 '10 at 22:46.
Well, when writing with bash, you can directly use every possible tool you have on the command line for your script. With any other language you would first have to execute that command and get some result etc. A simple script that (for example) gets a list of processes, runs through grep and gets some result would be a lot more complicated in other languages.As such, bash is still a good tool for writing quick things.
Many startup scripts are traditionally written as shell scripts and there doesn't seem to be a trend to move away from those. Shell scripts are perfectly suited for starting other processes and gluing their input/output together. That's an area where the other scripting languages are not as powerful.
Apart from that: even if languages like Perl, Python and Ruby become more and more ubiquitous, the only language that you're practically guaranteed on every unix-like system is the bourne shell ('though not necessarily in the form of bash) .
Apart from what others have said, I'd like to point out what's in my opinion the main reason to learn Bash: it's the (almost) standard Linux shell. Other scripting languages are surely useful, and maybe a lot more powerful, but what you'll be dealing with when you have a terminal in front of you is... Bash. Being able to manage I/O, pipes and processes, assing and use variables, and do at least some loop and condition evaluation is a must, if you want to manage a Linux system.
Easier, probably not. I actually prefer perl to bash scripting in many cases. Bash does have one advantage, though, especially on Linux systems: it's all but guaranteed to be installed.
And if it's not, its largely-compatible father (sh) will be, cause almost all system scripts are written for sh. Even perl isn't that ubiquitous, and it's everyfreakingwhere.
Bash is not only a scripting language, but it is a shell. Job control languages and shells Main article: Shell script A major class of scripting languages has grown out of the automation of job control, which relates to starting and controlling the behavior of system programs. (In this sense, one might think of shells as being descendants of IBM's JCL, or Job Control Language, which was used for exactly this purpose.) Many of these languages' interpreters double as command-line interpreters such as the Unix shell or the MS-DOS COMMAND.COM.
Others, such as AppleScript offer the use of English-like commands to build scripts. This combined with Mac OS X's Cocoa frameworks allows user to build entire applications using AppleScript & Cocoa objects. Python, Ruby and Perl are great, but are more general tools; in certain cases (embedded devices or other minimalistic systems) they can be considered bloat or in other situations they might pose a security risk (for environments where you want very high security and try to eliminate any unnecessary package).
In some cases shell scripts will perform much better due to closer integration with OS. Also, bash is production proven for myriad of administrative tasks and it is easy to find scripts that will cover very complicated scenarios (exceptions) and handle them gracefully.
If you do lots of GUI stuff, you'll probably only meet bash whenever you're doing some sort of customization on your own machine. Various hacks and stuff. If you use the command line to do stuff, bash is just indispensable.In fact, being good on the command line requires bash or some other shell familiarity.
I get miles out of having learned Bash when I wanted to navigate around my harddrive quickly. I wrote a navigation/menu interface that let me beam to different folders and files quickly and easily. Writing it in bash was simple and easy.
And there's lots of easily accessed, and free, stuff that'll show you how. Also, learning Bash is great for understanding how Unix and some of the core stuff really works -- and how far we've come with tools like Python.
In my experience, Perl meets something like 99% of any need that might require a shell script. As a bonus, it is possible to write code that runs on Windows sans Cygwin. If I won't have a Perl install on a Windows box I want to target, I can use PAR::Packer or PerlApp to produce an executable.
Python, Ruby and others should work just as well, too. However, shell scripting isn't all that complicated--at least things that you should be scripting in a shell aren't all that complicated. You can do what you need to do with a fairly shallow level of knowledge.
Learn how to read and set variables. How to create and call functions. How to source other files.
Learn how flow control works. And most important, learn to read the shell man page. This may sound facetious, but I am 100% serious--don't worry about cramming every detail of shell scripting into your brain, instead learn to find what you need to know in the man page quickly and efficiently.
If you find yourself using shell scripting often, the pertinent info will naturally stick in your brain. So, yes, basic shell is worth learning.
For a lot of tasks, bash can be very very concise. Code to search for a string in all the files of the current directory and print those lines: In bash: grep -ir "search_term" . In Python: for file in os.
Listdir('. '): file_content = open(file).readlines(). Split('\n') for line in file_content: if line.
Count("search_term") > 0: print file, ": ", line.
Bash (and the original Bourne sh and myriad derivatives) is - from one perspective - an incredibly high-level language. Where many languages use simple primitives, shell primitives are entire programs. That it might not be the best language to express your tasks, doesn't mean it is dead, dying, or even moribund.
You may get a true bournesh over at freshmeat (on Mac OS X, for example, /bin/sh is not a true bournesh). How to identify a traditional Bourne shell? ... A simple check for an often undocumented but characteristic feature: You can use the circumflex ^ (caret) as replacement for | (pipe).
I'm a perl guy, but the number of the bash (or ksh) functions I use and create on a daily basis is quite significant. For anything involved, I'll write a perl script, but for navigating the directory structure, and specifically for manipulating environment variables bash/ksh/... are indispensable. Again, especially for environment variables nothing beats shell, and quite a few programs use environment variables.In Perl, I have to write a bash alias or function that calls the Perl script, which writes out a temporary bash script, which then gets sourced after Perl exits in order to make the change in the same environment I'm launching from.
I've done this, especially for heavy-lifting on path variables. But there's no way to do it in just Perl (or python or ruby... or C-code for that matter).
Manipulating env vars seems like a week example to me. Certainly you can access manipulate env vars from within perl or whatever; you just can't export them back to bash. This is a limitation of the way variables are encapsulated in each subshell, not a limitation of any particular language.
– Quantum7 Dec 15 '10 at 23:13 @Quantum7, I don't get the "weak example". I don't consider passing modified env variables to subprocesses "manipulating environment variables", so I wasn't talking about that. I don't see how the rest applies.
I never said it was a matter of languages--it's obviously a matter of environment levels. Shell is an environment--Perl isn't (by itself). – Axeman Dec 16 '10 at 0:56.
As mentioned, the GNU tools are great, and are easiest to use within the shell. It is especially nice if your data is already in a linear or tabular form of plain text. Just as an example, the other day I was able to build a script to create an XHTML word cloud of any text file in 8 lines of Bourne Shell, which is even less powerful (but more widely supported) than Bash.
What I don't get is why people say bash when they mean any bourne-shell compatible shell. When writing shell scripts: always try to use constructs that also work in older bourne shell interpreters as well. It will save you lots of trouble some day.
And yes, there is plenty of use for shell scripts today, as the shell always exist on all unixes, out of the box, contrary to perl, python, csh, zsh, ksh (possibly? ), and so on. Most of the time they only add extra convenience or different syntax for constructs like loops and tests.
Some have improved redirection features. Most of the time, I would say that ordinary bourne shell works equally well. Typical pitfall: if!
Test $x -eq $y works as expected in bash that has a more clever builtin "if" operator, but the "correct" if test! $x -eq $y should work in all environments.
I think that a strong argument that python is not as natural as bash for many tasks is the simple fact that no one uses the python interpreter as their shell. Clearly this is possible: python> import os, subprocess python> os. Chdir("~/work") python> subprocess.
Call("vim","README") Clearly using python for a shell is absurd. Bash was designed for running other programs. Python was designed for doing computations.
While, most things can be done in either language, there will always be tasks that can be done more easily in bash than in python and vice versa.
Perl shells on the other hand, do exist see Zoidberg search.cpan. Org/~pardus/Zoidberg-0.94/lib/Zoidberg. Pm – Joel Berger Dec 16 '10 at 0:00.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.