Jump to navigation. Bash and Python are most automation engineers' favorite programming languages. Both have pros and cons, and sometimes it can be hard to choose which one you should use. Which language do you use more in your day-to-day work, Bash or Python? Please share in the comments. Here's the math: Bash has 3 nots, 2 lacks, 1 better, 1 poor, 1 great Python has 2 betters, 1 great. This is not football. A "scoresheet" doesn't help when you're trying to pick a language for a task.
First: look at your task. That's it. Sometimes, it will be Bash- scoresheet or no. I can tell you that Because bash is a domain specific language, not a general purpose programming language like Python. The confusion comes because Python all right in the system administration universe in many cases, but Bash's domain is exclusively there.
Comparing the languages is apples-to-oranges, quite honestly. It really depends on the task. Doing this in bash with curl is possible but ugly. Bash is the native language of Linux system administration. You put things in bash shell scripts that you would otherwise be typing into a shell prompt. Python is a programming language. You use it and other programming languages to do things that you would not otherwise accomplish by entering commands at a shell prompt.
Its not exactly apples to apples comparison, so it depends. I would prefer Bash for quick and small scripts over Python. Probably python, definitely for anything longer than few lines. There are also some nifty CLI tools be it git or skopeo which can be accessed from python see subprocess.
Popenshlex if they don't have equivalent Requests. On higher level Ansible comes to play To the fact, bash is a lot slower than python. GNU Bash being native Linux tool was simply designed to perform regular administrative tasks, some of us does use it for a lot other things, which is good to some extent.
Bash is slower except for the startup time compare to Python, but anyway the difference is so tiny to find a human noticeable difference.
They complete each other. I write lots of small bash scripts on linux, like I do powershell on windows.
I then run them through a modified subprocess and return response in json.Joinsubscribers and get a daily digest of news, geek trivia, and our feature articles. ZSHalso called the Z shell, is an extended version of the Bourne Shell shwith plenty of new features, and support for plugins and themes. ZSH has too many features to list here, some just minor improvements to Bash, but here are some of the major ones:.
Also for macOS users, you should probably use iTerm instead of the native terminal, as it has much better color support plus a lot of other features.
You can follow this guide to set that up and enable ZSH. Oh-My-Zsh is the most popular plugin framework for ZSH, and it comes with many built-in plugins and themes as well. There are also a couple of other plugin frameworks, including Antigenwhich is a full package manager for ZSH, but Oh-My-Zsh has loads of plugins built right in and does its job well. From there, you can enable and disable plugins by adding them to your.
You can get a full list of plugins on the Oh-My-Zsh repository. There are plenty of themes to go around, but powerlevel9k is by far the coolest. It adds a right-aligned info box, integration with git and command history, incredible customization, and wraps it all up in a slick interface based on the powerline plugin for vim. To set up powerlevel9k if you installed Oh-My-Zsh just clone the repository into the.
You can find the full documentation for powerlevel9k on the repo. Comments 0.
Subscribe to RSS
The Best Tech Newsletter Anywhere. Joinsubscribers and get a daily digest of news, comics, trivia, reviews, and more. Windows Mac iPhone Android. Smarthome Office Security Linux.
The Best Tech Newsletter Anywhere Joinsubscribers and get a daily digest of news, geek trivia, and our feature articles. Skip to content. How-To Geek is where you turn when you want experts to explain technology. Since we launched inour articles have been read more than 1 billion times.
Want to know more?This article is meant to show the main differences and advantages of the Z shell Zsh over the Bourne-again shell aka Bash. Zsh comes with a builtin compiler zcompile with which is possible to compile scripts or functions. The advantage of having a compiled version of a script or function is mainly speed.
It support floating point calculations Bash not and has a reach math function library. Finally Zsh support all the functionalities of Bash, so you can reuse any Bash script without changing anything. Some years ago, moved by an impelling need for change, I started using the Z shell. Coming from Bash and the KornShell kshI was at first quite lost, lost as you would be if you start using a vanilla bash without any prompt customization, aliases, colors, custom functions and so forth.
In my quest to find quickly the bit of information to setup Zsh for my needs, I discovered Oh My Zshan open source framework for managing your Zsh configuration.
Z shell vs Bash
It comes bundled with thousands of helpful functions, helpers, plugins and themes. Easy Peasy, I got my Zsh setup in a lightning bolt and forgot about my good intentions of learning the deepest secrets and niceties of Zsh.
As highlighted in the above table, with an additional plugin, Zsh has mouse support for basic actions, like text selection, copy and pasting. Functionality that usually is provided by the terminal itself. In the following terminal recording made with termtosvg you can see some of the main advantages of the Zsh completions and auto-corrections functionalities. While with additional plugins and scripts you can obtain almost the same functionalities with bash, Zsh provides these out-of-the-box.
As said, from a programming point of view, Bash and Zsh are quite the same, the most interesting difference are the math functions and the floating point support in Zsh. The function, zsh-newuser-install, will interactively help you to setup most of the default behaviour. It can be called by hand if it has been disabled or if you wish to start from scratch:.
This method is easier than setting everything by hand, but still a hurdle for those that do not know yet the basic Zsh builtin and functions. To alleviate the problem there are some different framework that hide all the difficulties and easy the setup. Just follow the installation instructions on their site, but do not forgot, afterwards, to read man zshall. October 26, - 9 mins shell Zsh bash unix.
Related Posts Shell tidbits.When we talk about UNIX based programming, it's usually about the shells, terminals, and the command line interfaces. The most prevalent shell in this regard is Bash but there are other variants available and used widely as well, like Zsh or the Z shell. In this article, we'll attempt to draw the line between the two shells and show the differences so you can get a sense of why you might use one or the other.
But first, in the following sections we'll introduce both shells before we compare them together. Zsh, or Z shell, was first released by Paul Falstad back in when he was still a student at Princeton University. Z shell is included in many operating systems, including Mac OS although it isn't the default that's actually used. Much like Bash, Z shell can basically be seen as an extended version of the Bourne shelland does contain a lot of the same features as Bash, which you'll probably notice in the sections below.
You may also notice that it pretty closely resembles the Korn shell as well. Some of the features that are worth mentioning include but are not limited to :. There are a lot more features than what we've shown here, but at least this gives you an idea as to how shells can be different. The Bash shell also known as the "Bourne-again shell" was also released around the same period as the Z shell in and Brian Fox is regarded as the creator behind it.
It was initially written as a replacement for the Bourne shell. Like a true replacement should, Bash is capable of executing all of the Bourne shell commands without a problem. There are quite a few features that the Bash shell has and some of the lesser-known ones include:. If you want to learn more, you can see a much larger list of Bash-specific features here. Now that we've give you a brief introduction to both of the shells, let's see how they hold up when actually compared and contrasted together.
The first thing to look at and one of the more significant aspects, in my opinion is prevalence and popularity of the shell.
While the Z shell has its fair share of users throughout the developer community, it's usually safer to write your scripts for Bash since there is a much larger group of people that will be able to run those scripts. The importance of adoption holds true for the public resources and documentation as well.
Thanks to its large community, Bash has quite a few more resources out there to help you learn how to use it. So, if you are planning on writing a script that you want many developers to easily be able to run then I'd recommend that you go with Bash. However, this shouldn't stop you from using Z shell if your end goal is more suited to Z shell. Finding the right solution to a problem is much more important than just using what's popular, so keep that in mind as well.
Although Bash is much more popular, that doesn't mean Z shell is without any useful features of its own. It's actually heavily praised for its interactive use, because it's more customizable than Bash. For example, the prompts are more flexible.
It can display a prompt on the left and another on the right side of the screen, much like vim's split screen. The auto-completion is also more customizable and is actually faster than Bash's. To give you a better sense of what kind of features Z shell has, here is a list of things that you will have access to when using Z shell over Bash:. There are also a bunch of features that are present in the Bash terminal but are absent from almost all of the other shells. Here are a few of them as well:.This article shows you how to set up some powerful tools in your command line interpreter CLI shell on Fedora.
If you use bash the default or zshFedora lets you easily setup these tools. You can give your terminal a new look by installing new fonts. Why not fonts that display characters and icons together? Powerline is a statusline plugin for vim, and provides statuslines and prompts for several other applications, including bash, zsh, tmus, i3, Awesome, IPython and Qtile.
You can find more information about powerline on the official documentation site. Oh-My-Zsh is a framework for managing your Zsh configuration. It comes bundled with helpful functions, plugins, and themes. To learn how set Zsh as your default shell this article. Once installed, you can select your theme. I prefer to use the Powerlevel10k.
One advantage is that it is times faster than powerlevel9k theme. To install run this line:. Close the terminal. When you open the terminal again, the Powerlevel10k configuration wizard will ask you a few questions to configure your prompt properly.
You can run the powerline10k wizard any time with the command p10k configure. Plug-ins are stored in. You can visit this site for more information. Install plug-ins means that you are going create a series of aliases or shortcuts that execute a specific function.
You can visit the official site for more information. Also, you can enable tab completion for colorls flags, just entering following line at end of your shell configuration:. A brand-new transient prompt feature was described in a Reddit post that allows a persistent fancy prompt at the bottom of the terminal, underneath historical commands with minimal prompts.
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Obviously Python is more user friendly, a quick search on google shows many results that say that, as Python is byte-compiled is usually faster. Most Linux applications, regardless what language the bulk of the program is written in, depend on shell scripts and Bash has become the most common.
Clicking an icon on the desktop usually runs a short Bash script. That script, either directly or indirectly, knows where all the files needed are and sets variables and command line parameters, finally calling the program. That's a shell's simplest use. Linux as we know it however would hardly be Linux without the thousands of shell scripts that startup the system, respond to events, control execution priorities and compile, configure and run programs.
Many of these are quite large and complex. Shells provide an infrastructure that lets us use pre-built components that are linked together at run time rather than compile time.
Those components are free-standing programs in their own right that can be used alone or in other combinations without recompiling. The syntax for calling them is indistinguishable from that of a Bash builtin command, and there are in fact numerous builtin commands for which there is also a stand-alone executable on the system, often having additional options. There is no language-wide difference between Python and Bash in performance. It entirely depends on how each is coded and which external tools are called.
Any of the well known tools like awk, sed, grep, bc, dc, tr, etc. Bash then is preferred for anything without a graphical user interface since it is easier and more efficient to call and pass data back from a tool like those with Bash than Python. To complicate matters Pythonlike most languages, can also call other executables, though it is more cumbersome and thus not as often used. One area where Python is the clear winner is user interface.
That makes it an excellent language for building local or client-server applications as it natively supports GTK graphics and is far more intuitive than Bash. Bash only understands text. Other tools must be called for a GUI and data passed back from them.
On Windows, PowerShell vs. Bash comparison gets interesting
A Python script is one option. Building with shell scripts is like assembling a computer with off-the-shelf components the way desktop PCs are. The best results are usually obtained by using a combination of languages where each can do what they do best.
One developer calls this " polyglot programming ". Generally, bash works better than python only in those environments where python is not available. Seriously, I have to deal with both languages daily, and will take python instantly over bash if given the choice.This is slightly off topic, but something I stumbled upon quite recently.
I'm sure veteran unix programmers would have encountered this too. I'll start off with something almost everyone knows - not all grep s are equal. Not all cut s are the same. There might be certain options available to binaries in one flavor that are not available to their equivalent binaries in a different flavor. Yesterday, I discovered that shell are by themselves quite different too.
It seems totally obvious right now, but when I encountered the bug, it puzzled me. I've tested it on an interactive shell, I've used it in shell scripts, so I know it works. Except, this time it didn't. Took me a while to zero in on this statement, but when I did, it shocked me. How does something so basic not work? When I started learning Linux inI was told I could use the dot-slash.
Turns out, I was using the syntax sh x.
And even though I had the interpreter in the first line of the script! The POSIX compliant shas it turns out, is not as rich as bash in features and cannot handle process substitution. So I had to ensure that bash was being used to execute the script, which I achieved by advising the human users not to use sh and also putting in a check for POSIX compliant execution. Anyway, the point is, something we take for granted could prove quite daunting when it pulls the rug out from under our feet.
I hope this information helps someone out someday! This goes again to show that when programming, one needs to be precise. If you mean to execute a command, call this command, not something else that you think will do the same thing. This also applies to data, like when one assumes a particular format, does a lot of work to reach incorrect conclusions just because the wrong piece of information was processed.
Bottom line: don't make assumptions or if you do, check that they are valid and report when they're not. Also, the more you learn, the more you question your basic assumptions. Because I was told sh shellScript.
I'm glad I made that error at last. These kind of assumption shattering insights happen very rarely :. Looks like I haven't yet graduated from the Ubuntu High School after all! I feel that a lot of people use the terms command lineshell and bash interchangeably. As a fan of the zsh I wince when that happens. I use pushdpopd and dirs with bash. I'll check out biozsh, thanks! Log In.