I wrote this slide deck. It was a presentation I made for a monthly "tech lunch" my team has.
I made it after a couple of weeks of messing with zsh. It was for an audience of 4 other people who knew less about zsh than me. I can't believe someone posted it to HN!
That explains the "this slide deck is getting traffic" email I got from Slideshare this morning.
Zsh won't mess with any of your configs. But even if it did, you'll probably never look back anyway once you make the switch. It does everything you're used to Bash doing, except more, and better.
I had just switched to zsh and found your deck when searching for something like "zsh features", I thought "hey this is great for starting out with zsh and maybe a good post for HN". Thank you for releasing it for everyone to see.
I'm glad that you and other people found some value in it. When I saw it here, I was worried the comments would tear it to shreds. :)
It was just a bit of a shock when I clicked the link. Since the link title was slightly different than what I named my slides, I just thought, "oh hey, another zsh comparison, let's see what this guy/gal said"...
Mostly, when submitting a post I refrain from changing the original title but I thought "How zsh is more useful than bash" would be better than the original. BTW I'd probably feel the same way too but the deck seems to be well received
That's actually the first time I've seen a decent set of reasons why zsh is worth using. Well done.
Almost every other "Switch from bash to zsh, it has this awesome killer feature" article I've seen has raved about a feature that's available in Bash & has been for years.
I'm starting at a new job in a month or so, I shall try & use it as an opportunity to switch to zsh since I won't have any can't-live-without bash shortcuts in place at that point.
(Last time I tried switch to zsh, it took OMZ to get it useable, but it also made it too slow to live with. Hopefully starting with a clean slate will do the trick)
> Almost every other "Switch from bash to zsh, it has this awesome killer feature" article I've seen has raved about a feature that's available in Bash & has been for years.
Yeah, I feel the same way. Most people seem to act like bash doesn't have tab completion or customizable prompts or something. This is actually the first time I've seen actual useful features of zsh that bash actually does not have (path expansion for instance). But I actually have my own little workaround scripts for those types of things that I'm used to so I don't feel a huge compelling reason to switch. The multiple shell history thing is a pretty good reason though. Maybe I'll switch eventually.
While zsh may be more 'useful', I find it a bit too smart. Many of the features are very interactive, and introduce a non-determinism that messes up my ability to fix errors. An example is command correction. I (usually) know when a command is wrong, and go to fix it without thinking. Being asked if you really meant some other command interferes with this, and while seemingly helpful, makes you wonder if a shell should really be doing that.
The directory listing shares the same problem. Once you have a list, it's just as easy to type the path then it's to cycle through the list (not that zsh stops this), it's just another interactive feature.
Then there is path-completion, which removes the / on the end of tab-completed paths. Since rsync treats a directory with / different to that without one, this feature annoys me to no end when using zsh.
I understand that all these are options, and could easily be configured. I just wonder how other people feel about them. Does anyone actively use these features? Do you find they can occasionally get in the way?
The command correction really bugs me in ZSH. 99% of the time it's wrong, and it doesn't learn even after the hundredth time of me telling it "no that's not what I meant, stick with the original". I keep thinking I should try writing a Bayesian filter for it or something, which would be a fun little project, but too low priority.
Also annoying when I start a command with sh, hit tab to command complete it with a .sh script in the current dir, and the command completion shows not just the .sh script but a bunch of shell commands as well. Pretty sure 'sh' should filter all those out and return only 'example.sh'. I don't recall this happening on bash.
Love all the plugins and things like oh-my-zsh, though.
Maybe I'm just not enough of a 'power user,' but I've been using Zsh since 2008 ~ 2009, and I rarely encounter the command-correction. The couple of times I've had it invoked were times where it correctly fixed a typo.
It does fix typos for me too, but most of the time asks weird things like, I typed 'aptitude' did I mean '.aptitude'? It loves misinterpreting some of my commands as dotfiles. Huh?
Then again I have a knack for unintentionally breaking computers, so maybe I've done something in env or rc that's messed it up...
I prefer not to configure much, the more I configure on my system, the harder it's to use another system (although, just using vim makes this hard on non-vim text editors.) Although I do find bash-completion handy in many situations (mainly for sub-commands), for mplayer it refuses to tab-complete videos not ending in a proper extension, which is rather annoying.
Don't get me wrong though, bash does have its bad points.
I like process substitution feature in zsh. In bash you can write:
vimdiff <(ls /bin) <(ls /usr/bin) [ It is an example. In real world, I use this feature for comparing outputs of one version of program with another one ]
And this will create two pipes, where output of each ls will go. Unfortunately, vimdiff sometimes needs to do second pass on the files, so this command won't work properly when outputs are large.
But in zsh you can write
vimdiff =(ls /bin) =(ls /usr/bin)
and this will create temporary normal files, instead of just pipes, and vimdiff will work fine.
I think the zsh-vs-bash debate is centered on minimalist vs. full-featured. For instance, the git completion example is very ugly in zsh to me. I know what git commands do, and I'd much prefer for the completion to take 1-2 lines total than one line per possible command, as in the zsh example. The prompt examples are similar -- my PS1 is
local green="$(tput setaf 2)"
local reset="$(tput sgr0)"
export PS1="\[$green\]>>\[$reset\] "
And a multiline prompt, let alone one with right-justified elements, is pretty gruesome to me.
The first slides about availability on Macintoshes don't resonate, because I'm going to have MacPorts on any dev box and use that to install the latest. It's more likely I ssh to a server that has Bash 4 and no Zsh than anything else, so it also makes sense to know bash and have a good .bashrc ready to scp up there if I'm going to be doing a lot of work on the server.
zsh spellcheck is very annoying, thankfully it can be disabled. This is my preferred spellcheck solution ;^) https://github.com/mtoyoda/sl
All that being said, zsh is a really cool piece of software. It's one of those things I've always wanted to really stretch to its limits, but I've never been able to hang with it for more than a few months, which I doubt is enough time to really become accustomed to the workflows zsh allows (like the /u/b/... expansion example in the slides).
Bash isn't really "minimalist" compared to the likes of dash or mksh. [rob-pike]Completion is a compromise, the Unix Way is to make your commands short and simple enough that you can memorize them all![/rob-pike]
local green="$(tput setaf 2)"
local reset="$(tput sgr0)"
export PS1="\[$green\]>>\[$reset\] "
Could be this in zsh:
export PS1="%{%F{green}%}>>%{%f%} "
- %{%} replace \[\]
- %F{color} sets the foreground colour
- %f resets the foreground colour
I would go with something like:
export PS1="%{%(?.%F{green}.%F{red})%}>>%{%f%} "
It will be green if the last command exiting successfully, otherwise it will be red.
There's also better history support (from my zsh config):
# History
# ~~~~~~~
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=$HOME/.zsh_history
setopt SHARE_HISTORY # Share history across sessions
setopt HIST_IGNORE_SPACE # commands starting w/ a space don't go into history
# SHARE_HISTORY seems to imply both of these, at least that's how the manpage
# reads, so let's comment them out for now.
#
# setopt INC_APPEND_HISTORY # Incrementally append history to file
# setopt EXTENDED_HISTORY # Save the timestamp and duration of commands to history file
Sorry, I just copy-pasted the whole thing. I know that most of the other options are available, though I didn't know that the HIST_IGNORE_SPACE was available in bash.
I'm unclear what you mean by foreground/background stuff. I'm looking at the manpage for bash 4.2, and I don't see any short-hand for the color escape codes in prompts.
Regarding the claim about Knuth's program being long, it is worth considering that (1) his program was primarily a demonstration of literate programming style, which contains considerable embedded documentation (2) the program needed to build significant basic infrastructure to support itself, including IO, sorting, case equivalence (including a table with each upper-case and lower-case letter), etc.
Doug's criticism and comparison of Knuth's solution vs. his own is insightful worth reading.
I don't use Plan 9, code in D or write LuaTeX, but I do use Emacs and wear a monocle. The last two are not a coincidence as the first (arguably more adequate substitute for God), invariably leads to the latter, most excellent eye wear.
And a note to my Mac friends : "Using csh is like trying to type with your feets[sic] (if you're used to zsh or ksh)."
I don't get your point. I use zsh+oh-my-zsh, and I don't know what Plan 9 is, don't code in D, never used LuaTeX (esp. not in Emacs), and I don't happen to wear a monocle.
In fact I find zsh much easier for beginners and people who don't master the arcane intricacies of *nix.
I -think- the (albiet, overly exaggerated) point is that if you only know zsh, you could potentially be at a disadvantage if you need to use someone else's terminal. Especially a remote server.
I don't think it's that much of a problem. My local machine is zsh, my linux servers run bash, my solaris hosts csh. Where ever I am, I just adjust to the local environment.
Only half his argument is a strawman. He's still correct that zsh is not omnipresent in the way that bash is, and therefore being proficient in bash is still very useful, regardless of the increase in productivity that putting the time into learning zsh would bring.
Both arguments are not sound though, and as a result demonstrably irrelevant. The title of the thread and the argument in the GP is based on features present in ZSH but not Bash and the benefits there of.
The OP's first argument is: for all operating systems Bash exists. Which, while also untrue is and unrelated to whether ZSH has features or improvements that Bash does not. OP's second argument is: all ZSH users also program in D...., which I won't even bother with.
For what it is worth, I use both Bash and ZSH. Their usage and knowledge there of is not mutually exclusive. The only issue I've encountered with using ZSH is that most build scripts expect to be ran from Bash and will run into issues when that is not the case sometimes, so I open Bash before running the command if I happen to be in ZSH at the time.
If I based my tool choices on popularity instead of their appropriateness for the problem domain my work flow would look much different as well.
One thing I don't see mentioned nearly enough is, if you're using extended globs, it's possible to tab-complete virtually all of it, which doubles as a handy reference.
For example:
setopt extglob
cd *(<tab>
~~ massive spam of possible glob qualifiers ~~
and it works for variable expansion modifiers as well:
print ${(<tab>
~~ completion candidates for parameter flags ~~
print ${<tab>
~~ complete any currently set variable in the current env~~
Another thing I like is the array types for things like $PATH that are historically colon-separated, typically
lower-case versions of the var name for the interesting 'magic' ones.
I do love the tagline "_Finally, a command line shell for the 90s_".
I was happy enough sticking to bash as it's the default shell everywhere, but since someone switched me to Zsh (using oh-my-zsh) I probably rely on the features too much to ever go back. I also hear https://github.com/sorin-ionescu/prezto is a nicer, cleaner fork of oh-my-zsh but I haven't so found the overwhelming desire to go through the switching pains.
I use fish. It's pretty fun to use. It has some pain points (most notably missing things like subshells and inline variable exporting) but it's in beta, so we'll see where it goes. I love the completions though, and it's definitely worth checking out for those alone.
I think you're getting your terminology mixed up: the bash man page calls what you described command substitution. Launching a subshell is something different and in bash it is done with parenthesis.
I tried fish for a while, and it's really great. The out of the box experience is way better than zsh and bash.
But I switched to zsh, mostly because I couldn't get used to the different syntax.
I just tried fish, way too slow. I held down the backspace key, and instead of deleting 10 characters, the entire line was gone. zsh is also too slow. bash may not have the bells and whistles, but it's at least super fast and doesn't get in your way.
1) A pretty great experience even before you start customizing. I only add a git status section to my status line and set some environment variables in my config.fish file.
2) An effort to clean up and orthogonalize shell syntax. The potential portability means I usually still make bash scripts when I'm sharing for others, but for my own stuff it's great.
3) Suggested completions. I start typing a command and if it's one I've used before in that directory it appears in faint gray letters on my command line and I just have to press ctrl-f to bring it up that way.
4) Probably a consequence of (1), but it feels very fast to me compared to when I used zsh. The author also talks about using threads and minimizing disk access to speed it up, but I don't really know how it compares to zsh on that level.
I don't care about experience before I start customizing because I am very certain that I will want to customize. A smaller configuration file does not benefit me at all.
I don't find zsh to be slow even on an older machine, so I'm puzzled what you mean by that.
Which only leaves the suggestion feature, which is interesting but not enough for me to pick up yet another shell with syntax that is even more different from the rest.
Oh-my-zsh is responsible for being slow as hell. If you really want plugins, Prezto probably still has what you want and is significantly faster on startup. (In my experience, with very minimal customization.)
i just tried fish. out of the box experience is great. not digging much yet but so far, so good. much faster start up time than zsh. this is 2013 already and i seriously dont' want a shell takes up a second or 2 to fire up.
I just tried fish and after half a minute declared it too slow: it is slow to complete (and not very good) and slow to print (or maybe slow to glob: "ls " takes far more time in fish than in bash or zsh).
I do not know if it has all I love in zsh (things like (.) or (om^/) or * or !$), but I would not trade zsh's completion for gaining 10% on startup time.
Current fish author here. Thanks for giving fish a try! I hope you tested a 2.0 branch build, and not the 1.x train from 2009 - a lot has changed since then, including major performance improvements. Check $FISH_VERSION if you are unsure.
'ls' is slower on fish because it passes the -G ("colorize”) flag to /bin/ls, which gives you nice colors, but requires a stat of each file to determine its type. If you want faster but uncolored output, you could redefine the ls function to invoke the ls command with no arguments:
fish passes the -G flag to 'ls' by default, which produces colorized output, but stats each file. So fish is actually outputting more information than zsh, and what your test is really measuring is the speed of '/bin/ls' vs '/bin/ls -G'
To compare ls speeds for the same workload, run it directly: /bin/ls. I expect no difference, because it is the same binary.
If you wish to compare globbing speeds, do not use bare ls, which does more work in fish. Instead, invoke the ls binary: '/bin/ls * '. Or better yet, just echo: 'echo *'.
I use bash as my everyday shell since 1996. I keep on reading the "how great zsh is" articles. And I always try zsh. But after a few minutes/hours, I go back to bash. It's really hard to change.
Just using zsh as a drop-in replacement for bash is pointless. You'd need to discover its features and customize it to get added value.
As a simple example, in bash if you use tab completion and there are multiple options, pressing tab again just reminds you that there are multiple options accompanied by a passive aggressive beep (it used to be this way at least). zsh lets you cycle through the possible completions.
> As a simple example, in bash if you use tab completion and there are multiple options, pressing tab again just reminds you that there are multiple options accompanied by a passive aggressive beep
This should fix it in bash:
bind '"\t":menu-complete'
I find the way ZSH does completions for git kind of frustrating. It's a bit overzealous and so when you try to complete a remote branch lie:
"git co br<tab>"
It finishes with:
"git co origin/branch"
Whereas what I want is:
"git co branch"
because I have git set up to automatically create a local branch and set it up to push to the remote when I do that. Just a small annoyance. Overall I find ZSH has cool features that don't actually work that well, or at least they don't do all that much for me. Spell checking, for example, is rarely that useful since it tends to show up for commands that work fine. It really needs an option to say "never correct this" but it doesn't.
That said I still use it, don't see any reason not too. I mean, Powerline for ZSH looks gooood. Just not sure it's that much better than other shells.
Only through zsh did I find out about tab auto-complete.
When I used bash, whenever I needed to uncompress a tarball I downloaded, I would type in the full, ~50 character filename. Only through zsh did I find out about tab autocomplete, and when I had to use bash on a friend's Mac, to my surprise, autocomplete worked.
For a while bash autocomplete was around, but you had to know to source it from /etc, which seems dumb. Now this stuff is sourced automatically[1].
[1] And sometimes they use it as a 'cheat.' virtualenvwrapper (on Ubuntu, and I assume Debain) is dropped into /etc/bash_completion.d/ instead of somewhere in $PATH. Meaning that it's auto-sourced for bash users, but zsh users need to know where it is, and source it. It seems stupid to put it in the bash_completion directory. Sure it has some completion stuff in it, but the bulk (and purpose) of the file is to setup a bunch of wrapper shell functions. It's like they didn't have a formal place to put it so they just jammed it somewhere.
I love using zsh (in combination with oh-my-zsh) on OSX but the only thing I've noticed after using it a year is that it's becoming very very slow. As in, it usually takes me 5-10 seconds to login to a new session (locally) and be able to see the prompt and type something.
Tab auto completion takes a second or two (even for files).
Combined with the git plugin I have enabled (which does "git status" on every prompt in a git folder) it's almost unbearable to work with.
I've looked into it a couple of times, there are some people with the same issues on oh-my-zsh's github, but I could never really solve it.
Would any pro zsh user know what my issue could be? I'm seriously considering going back to bash, I use it at work and it reminds me how fast the terminal can be.
I moved from OMZ to Prezto for this reason (its a fork of oh my). But prezto is slow too.
The only recourse I think is to go back to a clean zsh and build your own .zshrc. There are other leaner zsh "frameworks"[1] I have read of, but i intend going back to stock zsh soon.
If you like zsh don't go back to bash, just ditch oh-my-zsh and roll your own config gradually, or try prezto (oh-my-zsh fork which pays attention to performance).
> I love using zsh (in combination with oh-my-zsh) on OSX but the only thing I've noticed after using it a year is that it's becoming very very slow. As in, it usually takes me 5-10 seconds to login to a new session (locally) and be able to see the prompt and type something.
After using zsh for a while I moved back to bash. The main reason is that I want to learn bash well, because I might be writing shell scripts in the future and I don't want to use zsh specific features in my scripts so I don't want to get used to them.
Well I think there are if statements, loop conditions, and wildcard expansion that works in zsh but not in bash. So you could get used to something working in zsh, then you write an sh script with that thing, and then it doesn't work, and you have no idea why.
Example, I _think_ / (recursive globbing) works by default in zsh but not in bash. If you have / in a bash script without setting the right options then your script won't work and you will have no idea why until you've wasted a lot of time debugging.
I've been using zsh for a while now, mostly without using any special feature that isn't available (maybe with some tweaks) in bash.
The additional value for me is that I get all of this out of the box, or with not much effort. That's to oh-my-zsh I've got a nice looking theme (agnoster). Thanks to "zsh-syntax-highlighting" I get syntax highlighting, thanks to "history-substring-search" i got a nice way to search in my command history. All of those just took less than one minute to set up on my machine.
Luckily enough, I don't have to work over servers which may or may not have zsh, so i don't need to worry about that. Whenever I have to use a PC with bash (or any other *sh), I can easily get the same result, with a slightly-worse user experience.
Also, as a nice tip, zsh will complete "kill" and "killall". So that I don't have to fire up htop every time I want to kill a process.
Path expansion, can easily be fixed with something like this
in bash:
CDPATH=".:..:~:~/Desktop:~/Documents:~/Documents/Prj:~/bin:/usr/local:/usr/local/share:/opt/local"
for realm in ~/Library/Caches/temporaryitems ~/* ~/Desktop/* ~/Documents/* ~/Documents/Prj/* ~/Library/* ~/Library/Scripts/* ~/Library/
do
for folder in $realm
do
if [ -d ${folder} ]
then
* CDPATH="$CDPATH":"$folder"
fi
done
done
As for completions of git and such, that relies totally upon where you got your completion from.
There gotta be better arguments than this, and I am really sure there is.
I am on Mac OsX, and I downloaded and installed bash 4.2, and I have never experienced any problems with that.
My favorite feature that wasn't mentioned is completions for `kill`. For example, in bash I would have to `ps -ef | grep command_I_ran` then `kill -9 process_id_of_command_I_ran`. Bonus points if you can do that in one command! In zsh, you only need to do `kill -9 partial_command_i_ran[tab]` and it will complete it for you. Also, !$[tab] and the like. Also, you can set the theme to random to get a surprise every new window.
The only thing that is keeping me from 100% zsh is that zsh is not everywhere and bash is. When you switch companies, sometimes admins/IT are not flexible in allowing zsh to be installed on build/vnc servers. Can anyone share some tips on how to manage dotfiles for zsh with backwards compatible bash so that you can truely have a portable config?
Normally, these slideshares are difficult to follow since the subtleties of an actual presentation are missing. This is not the case here: kudos to the author. After reading the comments that I can transfer over all my .bash_* information, I will be doing so.
Not at all. ^site1^site2 would only work if it was your last command.
The idea, I believe, is when your browsing around multiple versions of the same directory structure. The 'cd site1 site2' allows you to jump directly to the equivalent directory in the other structure.
The equivalent in bash would be something like: cd `pwd | sed 's/tmp1/tmp2/'`
My personal favorite zsh specific feature is the REPORTTIME environment variable. When set to a nonzero number it'll automatically print a summary after a long running command.
I'm really glad I switched from bash to zsh a few years ago. zsh is, IMHO, a tiny bit better than bash in many areas. Because I use it all day every day, these little bits better add up to a lot of benefit.
I much prefer ksh myself, in particular for scripting. Fun fact about how bash is broken:
export a=0
cat $file | while read line
do
a=$(expr $a + 1)
done
Bash will fork the while loop as a separate process, inheriting (copying) its own environment, and the variable will only update locally, not in the parent process.
I thought every shell that is sh compatible would fork a while, and a for loop, as a matter of fact any loop into a sepearate process.
This comment however reminds me of some behaviour of bash 2.03 or earlier, where this behaviour was flawed, if you suddenly changed execution path during a recursion in a shell script. Sorry I can't describe it better, and that bash version, that was before 2.03 is long gone now!
I switched back from zsh to bash, and I miss it terribly. Problem is, I need to run both virtualenv and rbenv, and they're both designed for bash, and don't work properly with my zsh for some reason.
They're designed to mess around with your shell variables and environment to virtualize an environment for ruby or python. Unfortunately, they're not totally compatible with my customized zsh setup, and I don't have the time to rebuild and test a zshrc from scratch. Launching bash with them would be moot since I'd just have to spend my time in bash anyways, then.
Yes. Not only that but it has something even cooler: ESC + Q
Let's say you are about to finish a really long command and realize you should have done one other command first.
ESC + Q clears the current line, lets you enter a command, and then inserts the cleared line again on the next prompt. You have to try it to realize how cool it is.
I use Alt+# in bash to do something similar. It comments out the current line and gives you a new prompt. Then you can run whatever you wanted to do first, and then scroll up, delete the hash sign and hit Enter.
Bash is the gnu shell which is a superset not posix which is basic no frills mixture of minimal ksh and bourne syntax.
BSD has the almquist shell as it's /bin/sh and tcsh as it's /bin/csh. Various commercial vendors licensed the korn shell from bell labs. The korn shell is public domain and open for 13 years now. The default sh on most UNIX boxes are either ash or a hard link to ksh which emulates the POSIX definition of sh. zsh and bash also provide the option to hard or soft link so depending on your distro you may have /bin/sh linked to bash.
Debian at one point repackaged the BSD almquist shell as their system sh calling it dash mainly for speed and stability. I believe they removed it as their programmers apparently couldn't program system level scripts without their non portable bashisms or maybe just one of the NIH moments where everything must live under a single mono-cultural license and identity.
(about Debian use of dash)
> I believe they removed it ...
No, /bin/sh still points to dash in the latest and just released Debian stable (Wheezy). It seems to me that this transition was already completed in Sequeeze but I haven't checked.
I wrote this slide deck. It was a presentation I made for a monthly "tech lunch" my team has.
I made it after a couple of weeks of messing with zsh. It was for an audience of 4 other people who knew less about zsh than me. I can't believe someone posted it to HN!
That explains the "this slide deck is getting traffic" email I got from Slideshare this morning.