Zsh is a shell with many advanced command-line and scripting features.
64
votes
1answer
10k views
Difference between nohup, disown and &
What is the difference between
$ nohup foo
and
$ foo &
and
$ foo &
$ disown
28
votes
4answers
2k 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 ...
25
votes
4answers
2k 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 ...
22
votes
5answers
1k 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.
22
votes
3answers
1k 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 ...
22
votes
1answer
623 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, ...
21
votes
2answers
2k views
rebuild auto-complete index (or whatever it's called)
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, ...
16
votes
1answer
849 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 ...
15
votes
2answers
1k 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 ...
14
votes
1answer
1k 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 ...
13
votes
1answer
6k 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 ...
12
votes
1answer
527 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, ...
12
votes
3answers
1k 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 ...
11
votes
2answers
1k 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?
...
11
votes
1answer
767 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 ...
11
votes
2answers
216 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 ...
11
votes
1answer
322 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 ...
10
votes
3answers
3k 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 ...
10
votes
3answers
1k 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 ...
9
votes
1answer
1k 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 ...
8
votes
2answers
2k 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?
7
votes
3answers
2k 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 ...
7
votes
2answers
404 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 ...
7
votes
2answers
332 views
Shell Script for going through a dir recursively and chmodding based on conditions of file type
Can anyone point me to either code or a tutorial for writing a shell script that can recursively go through an entire directory structure (starting at the current working directory, or given an ...
7
votes
3answers
1k 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 ...
7
votes
4answers
247 views
mv * folder (avoiding 'cannot move' error) [duplicate]
Anytime I want to move thousands of files to a new folder, I always encounter the same problem.
> mkdir my_folder
> mv * my_folder
mv: cannot move 'my_folder to a subdirectory of itself ...
7
votes
1answer
1k 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 ...
7
votes
1answer
194 views
What is the difference between which and where
What is the difference between where and which shell commands?
Here are some examples
~ where cc
/usr/bin/cc
/usr/bin/cc
~ which cc
/usr/bin/cc
and
~ which which
which='alias | ...
7
votes
1answer
2k views
256 colour prompt in Zsh
How can I set my prompt to be colourized in 256 colours? I am looking for an equivalent to the bash prompt:
local DEFAULT="\[\033[0;39m\]"
local ROOK="\[\033[38;5;24m\]"
...
7
votes
2answers
1k views
Testing LS_COLORS in zsh
A few years ago I found an interesting code snippet that prints each type of file in its corresponding color according to the colors set up in LS_COLORS. Unfortunately, I can't remember the link ...
7
votes
3answers
348 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 ...
7
votes
3answers
380 views
Can I highlight the current prompt line in zsh?
Is it possible to highlight (set a background colour) for the whole line of the prompt in zsh? In my emacs config I have the line on which the cursor sits a slightly different colour to the window ...
7
votes
1answer
209 views
in zsh, how do I hide the backslashes in the completion menu
On Mac OS X 10.6, zsh. I have set in .zshrc:
setopt automenu
…to get a completion menu below the prompt. When I type:
cd <TAB>
I see a completion menu with all directories that have spaces ...
6
votes
3answers
927 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 ...
6
votes
4answers
2k 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 ...
6
votes
4answers
2k 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.
...
6
votes
3answers
932 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 ...
6
votes
2answers
101 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 ...
6
votes
2answers
408 views
Difference between alias in zsh and alias in bash
I have searched around but could not find anything conclusive. Is there a difference between the alias command in zsh and the alias command in bash? If not, does it mean I can share a set of aliases ...
6
votes
2answers
969 views
How do you make RPROMPT in zsh update itself on every enter?
My RPROMPT is set to display svn info using vcs_info. It reads RPROMPT=${vcs_info_msg_0_}. vcs_info is called using precmd(). However, RPROMPT doesn't update when I change directories. It works only ...
6
votes
1answer
336 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 ...
6
votes
2answers
557 views
What is word splitting? Why is it important in shell programming?
I'm getting confused about the role word splitting plays in zsh. I have not been exposed to this concept when programming in C, Python or MATLAB, and this has triggered my interest of why word ...
6
votes
3answers
3k views
How do I reverse a for loop?
How do I properly do a for loop in reverse order?
for f in /var/logs/foo*.log; do
bar "$f"
done
I need a solution that doesn't break for funky characters in the file names.
6
votes
1answer
245 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. ...
6
votes
2answers
921 views
List elements with spaces in zsh
I've been studying zsh scripting for all of 2 hours at this point and I've hit a wall. I want to go through a list of files that may have spaces in them. I'm open to completely different approaches ...
6
votes
2answers
1k views
Force title on GNU screen
By default, the title of a screen session is the name of the last command entered, which is fine for me, but in some cases I'd like to change it. I know the command Ctrl-A A, but it only changes the ...
6
votes
2answers
353 views
Directory shortcuts in emacs buffer
So I asked this question about directory shortcuts in a shell. The idea is I'd like to be able to open a file in /home/Documents/foo, say, by typing (C-x C-f) ~foo/file.
So, is there a way to emulate ...
6
votes
1answer
2k views
How to reset a shell environment?
This issue has been bugging me for a while, and although I've taught I've found my answer through EnvWatcher, unfortunately it only works on Bash. And I use zsh.
I would like to replicate the things ...
6
votes
2answers
360 views
zsh tab completion on empty line
I'd like a tcsh'ism that I haven't been able to find: On a blank line with no content, I want to press the tab key and see the equivalent of an ls. That is to say I want
$ <tab>
to do ...
6
votes
1answer
167 views
Ksh features incorporated into Zsh?
I have been a user of Bash for some time. I want to learn at least one other shell now, so I have been picking up the Korn Shell. However, it doesn't look like Ksh has had major updates for almost ...