Questions tagged [zsh]

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

Zsh (the Z shell) is a unix shell.

On the scripting front, zsh and incorporates many of ksh's programming features. Zsh's syntax resembles but is not fully compatible with Bourne-style shells, though zsh has Bourne and ksh emulation modes with compatible syntax and behavior. Zsh's advanced features include many extensions to variable expansion and globbing, associative arrays and more.

For interactive use, zsh's features include advanced line edition, advanced programmable completion, spelling correction, themable prompts and more. Zsh is highly customizable, with many options and tuning possibilities.

The zsh distribution includes add-ons in the form of loadable modules and functions: zmv for batch file renaming, the FTP client zftp, regular expressions, terminal handling, and many more.

Links and documentation

Related tags

  • Many shell-agnostic questions are of interest to zsh users.
  • (or globbing): matching files based on their name
  • a history of commands that can be navigated with the Up and Down keys, searched, etc.; also a recall mechanism based on expanding sequences beginning with !.
  • completion of partially-entered file names, command names, options and other arguments.
  • showing a prompt before each command, which many users like to configure.

Further reading

2897 questions
455
votes
3 answers

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

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 conditions under which they are sourced, but it is still not clear to me what…
kjo
  • 14,779
  • 25
  • 69
  • 109
266
votes
15 answers

Passing named arguments to shell scripts

Is there any easy way to pass (receive) named parameters to a shell script? For example, my_script -p_out '/some/path' -arg_1 '5' And inside my_script.sh receive them as: # I believe this notation does not work, but is there anything close to…
Amelio Vazquez-Reina
  • 40,169
  • 77
  • 197
  • 294
176
votes
3 answers

Why ZSH ends a line with a highlighted percent symbol?

I've noticed this on occasion with a variety of applications. I've often thought it was because the output was cancelled early (ctrl+c, for example) or something similar, and zsh is filling in a new line character. But now curiosity has gotten the…
jktravis
  • 2,156
  • 2
  • 13
  • 15
175
votes
1 answer

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 $VARIABLE would throw off the shell. I understand,…
kjo
  • 14,779
  • 25
  • 69
  • 109
151
votes
3 answers

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 statement true or false?
slm
  • 363,520
  • 117
  • 767
  • 871
134
votes
4 answers

Unlimited history in zsh

In zsh, I want to have unlimited history. I set HISTSIZE=, which works in bash. Now I import an old history mv old_history .history which is pretty big wc -l .history 43562 .history If I now close and start zsh again, I see wc -l .history 32234…
pfnuesel
  • 5,702
  • 8
  • 35
  • 60
117
votes
14 answers

How can I search history with text already entered at the prompt in zsh?

In zsh, I know that I can search history with Ctrl+r. However, oftentimes I start to type a command directly at the prompt, but then realize I should be searching history. When I hit Ctrl+r, it brings up a blank history search prompt like…
Sean Mackesey
  • 1,547
  • 2
  • 10
  • 14
116
votes
5 answers

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. I have a folder: ~/.my_zsh_functions In this…
Amelio Vazquez-Reina
  • 40,169
  • 77
  • 197
  • 294
113
votes
4 answers

How do you use the command coproc in various shells?

Can someone provide a couple of examples on how to use coproc?
slm
  • 363,520
  • 117
  • 767
  • 871
107
votes
11 answers

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 when I'm at the console (no X), which is often…
Lauritz V. Thaulow
  • 3,469
  • 4
  • 23
  • 22
105
votes
9 answers

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 access the hostname where the SSH session is coming…
stribika
  • 5,374
  • 5
  • 30
  • 35
105
votes
5 answers

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 bash?
chrisjlee
  • 8,283
  • 16
  • 49
  • 54
101
votes
3 answers

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 can the index (or whatever you call it) be…
phunehehe
  • 20,030
  • 27
  • 99
  • 151
97
votes
2 answers

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 syntaxes? Is $x iterating through a different type of…
Amelio Vazquez-Reina
  • 40,169
  • 77
  • 197
  • 294
97
votes
7 answers

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 that if I want to use which to see where my…
Adrian Petrescu
  • 1,077
  • 1
  • 9
  • 10
1
2 3
99 100