Zsh is a shell with many advanced command-line and scripting features.

learn more… | top users | synonyms (1)

57
votes
1answer
2k views

Have backticks (i.e. `cmd`) in *sh shells been deprecated?

I've seen this comment many times on Unix & Linux as well as on other sites that use the phrasing "backticks have been deprecated", with respect to shells such as Bash & Zsh. Is this ...
56
votes
9answers
2k views

Remember a half-typed command while I check something

I often find myself in the following position: I've started typing a long command at the bash prompt, but half-way through I find out I need to check something with another command. This is a problem ...
38
votes
4answers
3k views

What features are in zsh and missing from bash, or vice versa?

As a Linux user, I've always just used bash because it was the default on every distro I used. People using other Unix systems such as BSD seem to use other shells far more frequently. In the ...
37
votes
4answers
4k views

How to use `which` on an aliased command?

Like most users, I have a bunch of aliases set up to give a default set of flags for frequently used programs. For instance, alias vim='vim -X' alias grep='grep -E' alias ls='ls -G' The problem is ...
36
votes
4answers
4k views

Is there any way to keep a command from being added to your history?

Is there any way to keep a command from being added to your history? I have a command that I want to keep out of my history file, and I really don't care to have it there when I search the history ...
34
votes
2answers
5k views

Rebuild auto-complete index (or whatever it's called) and binaries in $PATH cache in zsh

After installing new software, an already opened terminal with zsh won't know about the new commands and cannot generate auto-complete for those. Apparently opening a new terminal fix the problem, but ...
28
votes
5answers
2k views

When do you use brace expansion?

I understand what brace expansion is, but I don't know how best to use it. When do you use it? Please teach me some convenient and remarkable examples if you have your own tip.
27
votes
1answer
834 views

Avoiding “BASH-isms” in shell scripts

Does there exist a tool similar to Perl::Critic that will inspect your shell scripts and point out flaws, portability issues, uses of non-standard programs without fallbacks, depreciated program uses, ...
22
votes
0answers
560 views

Completing avfs fake directories in zsh

How can I tweak zsh's completion system to complete “fake” files in some circumstances? More precisely, the AVFS filesystem exposes archives as directories by creating a “fake directory” next to ...
18
votes
4answers
6k views

How can I detect if the shell is controlled from SSH?

I want to detect from a shell script (more specifically .zshrc) if it is controlled through SSH. I tried the HOST variable but it's always the name of the computer which is running the shell. Can I ...
18
votes
4answers
833 views

Path independent shebangs

I have a script that I want to be able to run in two machines. These two machines get copies of the script from the same git repository. The script needs to run with the right interpreter (e.g. zsh). ...
18
votes
2answers
2k views

Display stuff below the prompt at a shell prompt?

Lets's say my prompt looks like this (the _ represents my cursor) ~ % _ Is there any way I could make it look like this ~ % _ [some status] The question was originally about zsh, but now has ...
18
votes
1answer
19k views

For loops in zsh and bash

I have noticed there are two alternative ways of building loops in zsh: for x (1 2 3); do echo $x; done for x in 1 2 3; do echo $x; done They both print: 1 2 3 My question is, why the two ...
18
votes
1answer
961 views

Using zsh's line editor to wrap around subprocesses

Is it possible to use zsh's built-in line editor (zle) to feed input to a subprocess? That is, I would like to run zlewrap mycommand where zlewrap is a zsh function and mycommand is any program that ...
17
votes
1answer
5k views

What should/shouldn't go in .zshenv, .zshrc, .zlogin, .zprofile, .zlogout?

The title says it all. I'm looking for guidelines on what one should and should not include in the various startup files for zsh. I understand the order of sourcing of these files, and the ...
16
votes
6answers
714 views

How to type several file names with fewer key strokes

If I want to convert a pdf to a png image with imagemagick I do something like: convert -trim -density 400 this_is_a_very_long_filename_of_my_pdf_file.pdf ...
16
votes
3answers
3k views

How to properly collect an array of lines in zsh

I thought the following would group the output of my_command in an array of lines: IFS='\n' array_of_lines=$(my_command); so that $array_of_lines[1] would refer to the first line in the output of ...
16
votes
3answers
5k views

make my zsh prompt show mode in vi mode

I use bindkey -v (for bash-ers set -o vi I think that works in zsh too) or vi(m) mode. but it bugs me that I don't have any visual cue to tell me whether I'm in insert mode or command mode. Does ...
16
votes
1answer
3k views

Is it possible to have vim key bindings in terminal?

I'm getting used to vim bindings (like pressing w to go to word, dw to delete a word, and such) and it's modes (insert, normal, visual), and, out of curiosity would like to know: is there some kind of ...
15
votes
1answer
4k views

How do I perform a reverse history search in ZSH's vi-mode?

I use vim for essentially all my editing needs, so I decided to once again try vi-mode for my shell (currently ZSH w/ oh-my-zsh on OS X), but I find myself trying (and failing) to use Ctrl-R ...
14
votes
4answers
1k views

Do we have more history for cd?

cd - can move to the last visited directory. Can we visit more history other than the last one?
14
votes
4answers
3k views

How to edit command line in full screen editor in ZSH?

In bash, using vi mode, if I hit Esc,v, my current command line is opened in the editor specified by $EDITOR and I am able to edit it in full screen before 'saving' the command to be returned to the ...
14
votes
1answer
1k views

zsh Interpret/ignore commands beginning with '#' as comments

In bash, if I type a command beginning with a '#', bash ignores it as a comment. Ie, the following is ignored at the bash prompt: > # Hi there! Whereas in zsh: > # Hi there ! zsh: bad ...
14
votes
1answer
922 views

In zsh, difference between cat <(cat) vs cat | cat vs cat =(cat)?

As a zsh/process substitution noob, I expected cat <(cat) and cat | cat to do the same thing: copy lines from stdin to stdout. My understanding was that both would execute a cat in a subshell, ...
14
votes
0answers
485 views

How to fix tab completion so it doesn't hide entries?

I'm using oh-my-zsh on Mac OS X with homebrew'ed zsh 4.3.12. I stumbled recently on a weird problem. In scripts/not-used I have several .R files: breakdowns.R eventloop.R ...
13
votes
2answers
826 views

How to background a command chain?

I want to background a command chain like cp a b && mv b c && rm a. I have tried doing cp a b && mv b c && rm a & but this only backgrounds the last process. How ...
13
votes
3answers
4k views

Switching to `zsh`: Are all bash scripts compatible with `zsh`?

I'm looking to switch from bash to zsh but concerned about compatibility of bash scripts. Are all bash scripts/functions compatible with zsh? Therefore, if that is true is zsh just an enhancement to ...
13
votes
3answers
2k views

How to delete part of a path in an interactive shell?

Is there a shortcut in bash and zsh to delete one component of a path? For example, if I type ls ~/local/color/, and the cursor is at the end of line, is there a shortcut to delete the color/ at the ...
13
votes
4answers
2k views

Share aliases and PATH setting between zsh and bash

The shell that I normally use is zsh. I have several aliases to enable color in some programs such as ls and grep. I've also set my custom path so that I can execute programs in non-standard place ...
13
votes
1answer
2k views

How to disable autocorrection for sudo [command] in zsh?

I have zsh and oh-my-zsh with default values and can't figure out how to turn off autocorrection for specific commands, that I often use, such as: sudo mc or sudo gem update. The thing is that I have ...
13
votes
2answers
363 views

Can I make `rm` interactive only when using globbing? (in either bash or zsh or both)

Whenever I rm multiple items at once with shell globbing and there's even the slightest possibility that the pattern expands to more than I expect it to, I always try to remember to add -i, but (of ...
12
votes
3answers
3k views

ESC key causes a small delay in terminal due to its Alt+ behavior

My terminal setup is gnome-terminal + tmux + zsh with vi bindings. In applications like vim or even in the zsh's command line vi editing mode, I need to frequently hit the ESC key but there is a ...
12
votes
6answers
1k views

Portable way to get script's absolute path?

What is a portable way for a (zsh) script to determine its absolute path? On Linux I use something like mypath=$(readlink -f $0) ...but this is not portable. (E.g., readlink on darwin does not ...
12
votes
2answers
2k views

zsh wants to correct vim to .vim

I'm using zsh on Gentoo x64, and when I type sudo vim /path/to/file from my home folder, zsh asks: zsh: correct 'vim' to '.vim' [nyae]? I want to run vim not my .vim folder. How do I fix this? ...
12
votes
1answer
1k views

When is double-quoting necessary?

The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of ...
12
votes
1answer
899 views

How does a fork bomb work?

WARNING DO NOT ATTEMPT TO RUN THIS ON A PRODUCTION MACHINE In reading the Wikipedia page on the topic I generally follow what's going on with the following code: :(){ :|:& };: excerpt of ...
12
votes
1answer
2k views

Add arguments from previous command to zsh completion

In zsh (as well as bash) you can use some history word expansions to denote arguments from previous commands. This example shows getting the 2nd parameter from the previous command in history with ...
12
votes
1answer
566 views

Dynamically update completion list in zsh

I find zsh's result lists for Tab completion quite useful, however I'd like to tweak their behaviour a bit: They should appear when I Tab for the first time and afterwards dynamically update with ...
11
votes
4answers
6k views

How to define and load your own shell function in zsh

I am having a hard time defining and running my own shell functions in zsh. I followed the instructions on the official documentation and tried with easy example first, but I failed to get it work. ...
11
votes
4answers
816 views

Search for a previous command with the same prefix when I press Up at a shell prompt

Coming from a FreeBSD world I wish to make the Linux terminal behave like FreeBSD one, especially the 9.1 version, basically when you type cd in the terminal and push the "up" arrow you can browse all ...
11
votes
2answers
4k views

In zsh how can I list all the environment variables?

I want to get a list of all environment variables (shell variables? exported variables?) and their values at a given time, in zsh. What is the proper way to do this?
11
votes
2answers
132 views

Cancel completion, but only completion, in zsh

When a completion function takes a long time, I can interrupt it by pressing Ctrl+C (terminal interrupt key, sends SIGINT) or Ctrl+G (bound to send-break). I am then left with the uncompleted word. ...
10
votes
2answers
2k views

How can I run a command in zsh without pushing it onto the current session's history?

Both bash and zsh support a shorthand of not placing a command in history if you prepend it with a space. This works great across sessions (if you've setopt histignorespace). However, the command is ...
10
votes
2answers
2k views

Make zsh completion show the first guess on the same line (like fish's)

In Fish when you start typing, autocompletion automatically shows the first autocompleted guess on the line itself. In zsh you have to hit tab, and it shows the autocompletion below. Is there anyway ...
9
votes
4answers
762 views

Can I reference a command before '&&' after '&&'

Not sure how else to phrase the question, but basically, I often find myself running a command like vagrant to bring up the VM, and then ssh into it like below: vagrant up && vagrant ssh ...
9
votes
2answers
570 views

How do I stop bash from syntax checking sourced files?

I have the following code in a file that is sourced by both zsh and bash. if test $SHELLNAME = zsh ; then lss() { l -l ${1:-.}/*(s,S,t); } laf() { l ${1:-.}/.*(.); } lad() { l -d ...
9
votes
4answers
3k views

Is it recommended to use zsh instead of bash scripts?

Can I assume that enough people have zsh installed to run scripts with a #!/usr/bin/env zsh as shebang? Or will this make my scripts un-runnable on too many systems? Clarification: I’m interested ...
9
votes
1answer
2k views

How to enable reverse search in zsh?

I recently switched to zsh (finally) and am loving it! So far one thing that I am missing is Ctrl+R to do incremental history search. I have the history set up properly HISTSIZE=10000 SAVEHIST=10000 ...
9
votes
1answer
538 views

What is the best way to detect (from a script) whether software is installed?

I've been frustrated before with differences in output from the which command across different platforms (Linux vs. Solaris vx. OS X), with different shells possibly playing into the matter as well. ...
9
votes
3answers
602 views

What is the main problem someone migrating from bash to zsh should face?

A few times I have had problems in bash that other using zsh didn't have and they were gloating about how smart they are. Also I have seen zsh users among people that I admire, and I have tried a ...