Questions tagged [zsh]

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

Filter by
Sorted by
Tagged with
465 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 ...
kjo's user avatar
  • 15k
268 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 receive them as: # I believe this ...
Amelio Vazquez-Reina's user avatar
178 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 ...
jktravis's user avatar
  • 2,176
176 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 $...
kjo's user avatar
  • 15k
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 ...
slm's user avatar
  • 366k
136 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 ...
pfnuesel's user avatar
  • 5,782
120 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. ...
Amelio Vazquez-Reina's user avatar
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 ...
Sean Mackesey's user avatar
115 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's user avatar
  • 366k
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 ...
Lauritz V. Thaulow's user avatar
106 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 ...
chrisjlee's user avatar
  • 8,393
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 ...
stribika's user avatar
  • 5,404
102 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 ...
phunehehe's user avatar
  • 20.1k
99 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? ...
Amelio Vazquez-Reina's user avatar
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 ...
Adrian Petrescu's user avatar
95 votes
3 answers

How to view datetime stamp for history command in Zsh shell

When I run the history command on my ubuntu server, I get output as follows: history ... 25 cd ~ 26 ls -a 27 vim /etc/gitconfig 28 vim ~/.gitconfig I want to view the datetime ...
JohnMerlino's user avatar
  • 6,001
91 votes
1 answer

Command history in Zsh

How does Zsh keep track of command history? I see two files in my home directory: .zhistory and .zsh_history. What is the difference between them? The files seem to contain all of my history. Does ...
Amelio Vazquez-Reina's user avatar
90 votes
6 answers

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 ...
Murali Suriar's user avatar
90 votes
4 answers

Using OR patterns in shell wildcards

Contents of my dir are $ ls -lrt total 0 -rw-r--r-- 1 user1 admin 19 Oct 8 12:31 night.txt -rw-r--r-- 1 user1 admin 19 Oct 8 12:31 noon.txt -rw-r--r-- 1 user1 admin 38 Oct 8 12:31 day.txt I ...
mtk's user avatar
  • 27.2k
89 votes
4 answers

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 ...
xenoterracide's user avatar
83 votes
3 answers

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 ...
sharat87's user avatar
  • 4,219
81 votes
3 answers

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 ...
Ali's user avatar
  • 6,773
80 votes
7 answers

How many shells deep I am?

Problem: Find how many shells deep I am. Details: I open the shell from vim a lot. Build and run and exit. Sometimes I forget and open another vim inside and then yet another shell. :( I want to ...
Pranay's user avatar
  • 951
80 votes
4 answers

What's the newline symbol in zsh's PS1?

I'm trying to setup a multiple line PS1, for zsh, but \n doesn't was parsed by zsh, PS1="%~\n %> " How should I set it up?
daisy's user avatar
  • 54k
79 votes
3 answers

How to get rid of "No match found" when running "rm *"

Using zsh, I get a "No match found" message when choosing a pattern that does not fit with rm and that even when redirecting the output. # rm * > /dev/zero 2>&1 zsh: no matches found: * ...
user123456's user avatar
  • 4,948
76 votes
2 answers

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 ...
Hank Gay's user avatar
  • 3,499
76 votes
8 answers

Making zsh default shell without root access

I am using my school's computers and would like to use zsh instead of bash. I'd like to make it the default shell, but I cannot run a command such as $ chsh -s $(which zsh) because I don't have admin ...
goodcow's user avatar
  • 913
73 votes
5 answers

zsh: How to check if an option is enabled

To enable an option, we can use setopt. e.g.: setopt extended_glob How can we check if an option is currently enabled ?
Sébastien's user avatar
72 votes
1 answer

What is the difference between the "...", '...', $'...', and $"..." quotes in the shell?

Sometimes I see shell scripts use all of these different ways of quoting some text: "...", '...', $'...', and $"...". Why are there so many different kinds of quote being used? Do ...
Michael Homer's user avatar
69 votes
1 answer

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 ...
Somebody still uses you MS-DOS's user avatar
68 votes
5 answers

history isn't preserved in zsh

Whenever I open a new instance of a terminal, the history is empty. Why is that? Do I need to set something up? In bash there's no need for this, though.
user avatar
67 votes
3 answers

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 ...
Amelio Vazquez-Reina's user avatar
66 votes
7 answers

Ctrl + left/right arrow keys issue

After the last system update the ctrl + left/right arrow command on zsh terminal doesn't do anything. Also ctrl+ u has something wrong because usually that command erase from the cursor to the ...
riskio's user avatar
  • 951
63 votes
2 answers

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?
Ali's user avatar
  • 6,773
63 votes
16 answers

How to cd automatically after git clone?

I want to automatically cd to the directory created by the clone command after I git cloned something. Important: I don't want to alter the syntax for the command (e.g. use an alias/function) because ...
wildeyes's user avatar
  • 1,155
63 votes
6 answers

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 ...
Macha's user avatar
  • 3,780
60 votes
15 answers

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?
Tim's user avatar
  • 100k
59 votes
7 answers

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.
58 votes
12 answers

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 ...
xenoterracide's user avatar
57 votes
7 answers

Unix-portable way to get script's absolute path in zsh?

What is a portable1 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 ...
kjo's user avatar
  • 15k
56 votes
3 answers

How can I expand a quoted variable to nothing if it's empty?

Say I have a script doing: some-command "$var1" "$var2" ... And, in the event that var1 is empty, I'd rather that it be replaced with nothing instead of the empty string, so that the command ...
muru's user avatar
  • 71.3k
55 votes
1 answer

pushd, popd vs cd, cd- in bash and zsh

Is there a difference between the behavior of pushd/popd in bash vs zsh? It seems in zsh cd, cd- behaves exactly the same as pushd/popd (which adds/pops directory automatically when cd) while in bash ...
dragonxlwang's user avatar
52 votes
2 answers

How to disable "auto cd" in zsh with oh-my-zsh

Googling this didn't show up any results. Here's what I mean: I have a binary file named x in my path (not the current folder, but it is in the PATH), and also a folder with the same name in the ...
Gabi Purcaru's user avatar
52 votes
4 answers

How to change default shell to ZSH - chsh says "invalid shell"

I installed ZSH on a VM of mine, where I compiled it from source. The location of ZSH is /usr/local/bin/zsh when I run chsh -s /usr/local/bin/zsh it outputs chsh: /usr/local/bin/zsh is an invalid ...
Zach Russell's user avatar
  • 1,037
50 votes
3 answers

How to 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 ...
korylprince's user avatar
  • 1,811
50 votes
5 answers

What does `zstyle` do?

zstyle seems like it's just a central place to store and retrieve data, like an alternative to export-ing shell parameters. Is that true, or is there more to it?
shadowtalker's user avatar
  • 1,278
50 votes
3 answers

scp wildcard not working in zsh

I have switched over to zsh, and it is working fine. One strange thing, when I try to scp with a * wildcard, it does not work, and I have to drop into bash. The second command below works fine. Any ...
port5432's user avatar
  • 941
50 votes
2 answers

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

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 ...
Nevir's user avatar
  • 603
50 votes
3 answers

what is the zsh equivalent of bash's export -f

So I started using zsh. I like it all right. It seems very cool and slick, and the fact that the current working directory and actual command line are on different lines is nice, but at the same time, ...
ixtmixilix's user avatar
  • 13.1k
49 votes
6 answers

How can I have two keystrokes to delete to either a slash or a word in zsh?

Bash behaviour I've just migrated from bash to zsh. In bash, I had the following line in ~/.inputrc. "\e\C-?": unix-filename-rubout Hence, Alt+Backspace would delete back to the previous ...
Sparhawk's user avatar
  • 19.8k

2 3 4 5