Moving from bash to zsh


For someone who never learned “computers” in school, I’m actually pretty fond of the command line interface. I was one of those kids who was lucky enough to have a computer at home since before I was born. The first operating system I could remember using was MS-DOS. So it was very important to learn the command line so I could load and play games.

And that’s also why, more than twenty years later, I must have DOSBox installed in every machine I own. It’s an emulator that let’s you play all the DOS games that you grew up with.

Back to the topic at hand. As a web developer, using the terminal is part and parcel of my day. But other than installing iTerm2 and customising its colour scheme, I never really did anything more. I recently chanced upon this article by Mike Buss on optimising the terminal experience and decided to try it out as well.

What is shell?

Shell is simply a command line interface (CLI) that allows users to interact with the computer’s...

0 0

Zsh can handle bash completions functions. The latest development version of zsh has a function bashcompinit, that when run will allow zsh to read bash completion specifications and functions. This is documented in the zshcompsys man page. To use it all you need to do is run bashcompinit at any time after compinit. It will define complete and compgen functions corresponding to the bash builtins.

bash completions are typically stored in files which must be sourced (bash doesn't have autoloadable functions) I use the following function to source these files:

bash_source() { alias shopt=':' alias _expand=_bash_expand alias _complete=_bash_comp emulate -L sh setopt kshglob noshglob braceexpand source "$@" }

This uses aliases to avoid the bash shopt builtin and to avoid problems with common bash functions that have the same name as zsh ones. It also sets zsh options to best emulate bash.

It is probably better to use function autoloading however.


0 0


I spend pretty much my entire day inside the terminal. Upon first being introduced to CLI it seemed outdated and archaic. I eat those words pretty hard now. I've primarily used bash for everything becuase it's the defacto solution on many platforms. It's been versatile but it always felt like something was missing. I decided to do some researching to figure out if there was some kind of other alternative to try using. I came up with ZSH and prezto, I did look at oh-my-zsh as well but ultimately decided to go with prezto. Prezto seemed to align more with what I was trying to make my bash shell do but with much more functionality and less hassle. The best part is switching didn't mean I had to revamp my old way of doing things on the command line. I use my .vim folder as a toolkit of sorts, I think I've mentioned this in other posts, by keeping it in git and then syncing it wherever I go. I kept my old bash config files and simply sourced them in my zshrc. This was...

0 0

So, you hate using a terminal? That might be, because you use the arrow keys to navigate character by character through a long command just to change a paramater at the other end of the line, right? Here's a list of my most-used bash & zsh shortcuts, that will definitely boost your productivity and will help you to improve your command line experience.

History Search

Press CTRL + R to search through the history. Continue pressing CTRL + R until you find the entry you're looking for. Press [ENTER] to execute the current expression. Press [Right Arrow] to modify the current expression. Press CTRL + G to escape from search mode.

Special setup for Mac OS X

Go to Terminal -> Preferences -> Settings -> Keyboard

To enable the use of the ALT or OPTION key, select use option as meta key To enable the CTRL + [left arrow] and CTRL + [right arrow] shortcuts, select control cursor left and set it to \033b and control cursor right and...
0 0

Zsh is a powerful shell that operates as both an interactive shell and as a scripting language interpreter. While being compatible with Bash (not by default, only if issuing emulate sh), it offers advantages such as improved tab completion and globbing.

The Zsh FAQ offers more reasons to use Zsh.


Before starting users may want to see what shell is currently being used:

$ echo $SHELL

Install the package. For additional completion definitions, install the package as well.

Initial configuration

Make sure that Zsh has been installed correctly by running the following in a terminal:

$ zsh

You should now see zsh-newuser-install, which will walk you through some basic configuration. If you want to skip this, press q. If you did not see it, you can invoke it manually with

$ zsh /usr/share/zsh/functions/Newuser/zsh-newuser-install -f

Making Zsh your default shell

See Command-line shell#Changing your default...

0 0

Windows 10’s Anniversary Update offers a big new feature for developers: A full, Ubuntu-based Bash shell that can run Linux software directly on Windows. This is made possible by the new “Windows Subsystem for Linux” Microsoft is adding to Windows 10.

What You Need to Know About Windows 10’s Bash Shell

This isn’t a virtual machine, a container, or Linux software compiled for Windows (like Cygwin). Instead, Windows 10 gains a Windows Subsystem for Linux, which is based on Microsoft’s abandoned Project Astoria work for running Android apps on Windows.

Think of it as the opposite of Wine. While Wine allows you to run Windows applications directly on Linux, the Windows Subsystem for Linux allows you to run Linux applications directly on Windows.

Microsoft has worked with Canonical to offer a full Ubuntu-based Bash shell that runs atop this subsystem. Technically, this isn’t Linux at all. Linux is the underlying operating system kernel, and that...

0 0

Bash is the default shell in Mac OS X and has been since 10.3, it’s generally considered to be the de facto shell standard in the unix world. That said, there are some people who prefer to use the tcsh shell, or perhaps you just want to break away from the norm. Changing the default shell is pretty easy, but you will likely run into problems when running bash shell scripts. If you want to experiment with tcsh and use it as your default shell, here’s how to do it from the GUI in three easy steps:

Change the default shell from bash to tcsh as used by Terminal app in three steps:

Launch From the Terminal menu, select preferences In preferences, select “execute this command” and type /bin/tcsh in place of /bin/bash

That’s it. Now anytime you open a new terminal it will be the tcsh shell. To revert back to bash, follow the same procedure but replace /bin/tcsh with /bin/bash.

Note: most shell scripts for OS X are written specifically for...

0 0
Bash and Zsh are both shells for your terminals. Bash or the Bourne-Again SHell, is the default on most systems due to backward compatibility reasons with sh which was pretty much the only shell in its time.

Before I begin elaborating on the differences, there should come the most important item, the direct quote from the ZSH Documentation:

2.5: Similarities with bash

The Bourne-Again Shell, bash, is another enhanced Bourne-like shell; the most obvious difference from zsh is that it does not attempt to emulate the Korn shell. Since both shells are under active development it is probably not sensible to be too specific here. Broadly, bash has paid more attention to standards compliancy (i.e. POSIX) for longer, and has so far avoided the more abstruse interactive features (programmable completion, etc.) that zsh has.

Now that the documentation is out of the way, let me begin discussing the topic based on my own views. Bash and Zsh are bot undeniably powerful shells...
0 0

As a long time shell user I've spent a lot of time using bash as my default shell. In most of the hosting environments I regularly use bash is the default shell. Because of this bash is what I've been using on my local development machine until I recently switched to Zsh and oh-my-zsh. This post outlines why I prefer Zsh and how I made the switch.

Why I Prefer Zsh

There are a few reasons that Zsh has really popped for me.

In the image above you can see my current Zsh config in action. This theme allows me to see details about my system and the current working directory. oh-my-zsh ships with a bunch of themes and you can create your own. I love plugins. My CMS of choice has them. My text editor has them. Why shouldn't my terminal. Zsh has them and oh-my-zsh ships with a bunch of useful ones like git integration, github, osx, and so much more. Because of it's compatibility with bash commands I only had to learn the new stuff such as how to use the...
0 0
0 0
0 0

Parsing the output of ls is not reliable.

Instead, use find to locate the files and sort to order them by timestamp. For example:

while IFS= read -r -d $'\0' line ; do file="${line#* }" # do something with $file here done < /dev/null | sort -z -n)

What is all this doing?

First, the find commands locates all files and directories in the current directory (.), but not in subdirectories of the current directory (-maxdepth 1), then prints out:

A timestamp A space The relative path to the file A NULL character

The timestamp is important. The %T@ format specifier for -printf breaks down into T, which indicates "Last modification time" of the file (mtime) and @, which indicates "Seconds since 1970", including fractional seconds.

The space is merely an arbitrary delimiter. The full path to the file is so that we can refer to it later, and the NULL character is a terminator because it is an illegal character in a file name and thus lets us know for...

0 0

The most popular is bash. The best is zsh, but it's not so much better than bash to convince many people to change their habits.

Using csh or sh is a mistake. You should only use ksh if you're forced to (bash is not available). If a script must have good portability, either use sh and be aware of what features are unique to your implementation, or consider bash as it's quite widespread.

I have seen people who are significantly more comfortable with tcsh to prefer it over bash.

I think it makes sense to habitually use the same shell for interactive use as for scripts. I recommend zsh to people who are newly learning and who have control over their environment, but bash to people who are already slightly comfortable with it. People who may have old shells forced on them or be forced to maintain old scripts should get comfortable with sh, csh, and ksh.

My comments come from the bias of someone who uses bash regularly, occasionally notices zsh, says "that's...

0 0

I'm a korn-shell bigotveteran, so make sure that I speak from a certain perspective.

I am comfortable with Bourne shell, ksh88, and ksh93, and I know which features are supported in which.

For interactive use, take whatever fits your need. Experiment. I like being able to use the same shell for interactive use and for programming.

I went from ksh88 on SVR2 to tcsh, to ksh88sun and ksh93. I tried bash, and hated it because it flattened my history. Then I discovered

shopt -s lithist

and all was well. (The lithist option assures that newlines are preserved in your command history.)

For shell programming, I'd seriously recommend ksh93 if you want a consistent programming language, good POSIX conformance, and good performance, as many common unix commands can be available as builtin functions.

If you want portability use at least both. And make sure you have a good test suite.

There are many subtle differences between shells. Consider for...

0 0

One thing to bear in mind is that bash implemented arrays like ksh, that is as associative arrays where keys are limited to positive integers (contrary to other languages like perl or zsh for instance).


a[123]=foo a[456]=bar a[789]=baz

In bash, you've got an associative array with 3 elements, while in perl, you'd have an array with 790 elements (789 with zsh).

In ksh or bash, ${a[@]:0} returns the first element of the array in the list of elements sorted by indices. So in that case, it returns ${a[123]}, not ${a[0]}.

unset 'a[123]'

(remember to quote it, otherwise it would fail if there was a file called a1 or a2 or a3 in the current directory) makes sense, as it removes a particular key in the array.

unset 'a[@]::2'

makes less sense though. bash only understands unset a, unset 'a[123]' or unset 'a[*/@]', anything after is ignored, so unset 'a[@]::2' and unset 'a[@]please' do the same: unset the whole array.

If you want to unset a range...

0 0

bash on Mac OS X


David Miller


If you're curious about this article, chances are you've played around with the Terminal in OS X and have become accustomed to the command-line interface, or you've worked with files through commands that you type rather than menus and icons that you click. If that's not the case, then you should first read Chris Stone's series of articles, titled "Learning the Mac OS X Terminal", and "Learning the Terminal in Jaguar."

In the switch from Jaguar to Panther, one of the footnotes that has occasionally been mentioned is the switch from tcsh to bash as the default shell in Mac OS X. Those who upgraded from Jaguar to Panther will still be using tcsh when they log in to Panther for the first time since your existing preferences will be respected; only new accounts that are created from within Panther will use bash by default. Most casual Terminal users won't notice...

0 0

This is a book that clearly targets beginners, people with close to no experience with Linux and the bash shell. If you work on a daily basis with the penguin, you better move along.

Ok so, let's imagine I recently moved from Windows to Linux and I want to explore what the bash shell offers me. What do I get off these 300 pages? Well, the book is divided in 3 parts:

Very basic shell features.
Basic shell scripting.
Basic shell features.

The first part, which covers the first three chapters, tells you about basic commands, such as "ls" and all the arguments it swallows. Unless you have never opened the terminal before, you might want to skip these pages.

Next the authors introduce some basic shell scripting, starting from variable naming to arrays and flow control. This was, by far, the most interesting part of the whole book in my opinion, but still, the authors have covered only the very basics. What I've found particularly annoying was the...

0 0