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
283k views

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
397k views

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 ...
Amelio Vazquez-Reina's user avatar
178 votes
3 answers
73k views

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
76k 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 $...
kjo's user avatar
  • 15k
151 votes
3 answers
34k 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 ...
slm's user avatar
  • 366k
136 votes
4 answers
95k views

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
153k 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. ...
Amelio Vazquez-Reina's user avatar
117 votes
14 answers
131k views

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
39k views

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
8k 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 ...
Lauritz V. Thaulow's user avatar
106 votes
5 answers
102k views

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
58k 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 ...
stribika's user avatar
  • 5,404
102 votes
3 answers
31k 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 ...
phunehehe's user avatar
  • 20.1k
99 votes
2 answers
173k 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 syntaxes? ...
Amelio Vazquez-Reina's user avatar
97 votes
7 answers
35k 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 ...
Adrian Petrescu's user avatar
95 votes
3 answers
58k views

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
142k views

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

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
25k 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 ...
xenoterracide's user avatar
83 votes
3 answers
23k 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 ...
sharat87's user avatar
  • 4,219
81 votes
3 answers
60k 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 ...
Ali's user avatar
  • 6,773
80 votes
7 answers
14k views

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
59k views

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
83k views

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

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
19k views

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
13k views

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

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

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

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
19k 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 ...
Macha's user avatar
  • 3,780
60 votes
15 answers
19k 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?
Tim's user avatar
  • 100k
59 votes
7 answers
19k 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.
58 votes
12 answers
40k 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 ...
xenoterracide's user avatar
57 votes
7 answers
41k views

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
12k views

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
44k views

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
24k views

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
86k views

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
59k views

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
36k views

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
30k views

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
26k views

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
22k views

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
15k views

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

1
2 3 4 5
59