Tag Info

Citing the Open Group Specification on Shell Command Languages,
specifically this section "2.6.3 Command Substitution" this statement regarding
backtick's deprecation is actually false. Both forms of the command
substitution, backticks (`..cmd..`) or dollar parens ($(..cmd..)) are still supported in so far as the specification goes.
excerpt
Command ...

which is actually a bad way to do things like this, as it makes guesses about your environment based on $SHELL and the startup files (it thinks) that shell uses; not only does it sometimes guess wrong, but you can't generally tell it to behave differently. (which on my Ubuntu 10.10 doesn't understand --skip-alias as mentioned by @SiegeX, for example.) type ...

To rebuild the cache of executable commands, use rehash or hash -rf.
Make sure you haven't unset the hash_list_all option (it causes even fewer disk accesses but makes the cache update less often).
If you don't want to have to type a command, you can tell zsh not to trust its cache when completing by putting the following line in your ~/.zshrc¹:
zstyle ...

Do ctrl-A to get to start of line, prepend a hash and press return - this way it will stay in the command history as a comment and you can get back to it with cursor up
EDIT: just noticed this is a slightly more elegant variant on your #2 ;)

A somewhat faster version of alex's Ctrl+A Ctrl+K (which moves to the front of the line and then cuts everything forward) is to just use Ctrl+U, which cuts backward on bash, and the entire line (regardless of your current position) on zsh. Then you use Ctrl+Y to paste it again

Brace expansion is very useful if you have long path names. I use it as a quick way to backup a file:
cp /a/really/long/path/to/some/file.txt{,.bak}
will copy /a/really/long/path/to/some/file.txt to /a/really/long/path/to/some/file.txt.bak
You can also use it in a sequence. I once did so to download lots of pages from the web:
wget ...

There's already been quite a bit of activity on the topic on other Stack Exchange sites. My experience of switching from bash to zsh, as far as can remember (it was years ago²), is that I didn't miss a single thing. I gained a lot; here are what I think are the simple zsh-specific features that I use most:
The zsh feature I most miss when I occasionally ...

In ZSH:
First set HIST_IGNORE_SPACE in your profile and then prefix the commands you don't want stored with a space.
From the man page, the following 3 options can be used to say that certain lines shouldn't go into the history at all
HIST_IGNORE_SPACE don't store commands prefixed with a space
HIST_NO_STORE don't store history (fc -l) command
...

Here are the criteria I use in my ~/.profile:
If one of the variables SSH_CLIENT or SSH_TTY is defined, it's an ssh session.
If the login shell's parent process name is sshd, it's an ssh session.
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
SESSION_TYPE=remote/ssh
# many other tests omitted
else
case $(ps -o comm= -p $PPID) in
...

There's checkbashisms. On Debian, it's shipped as part of the package maintainer tools.
Test your scripts under dash and posh. Both have a few non-POSIX constructs, but if your script works in both, it's likely to work in most places. (With the caveat that it's difficult to test typical shell scripts as they tend to have a lot of corner cases.)
If you ...

First mistake (→ Q2): IFS='\n' sets IFS to the two characters \ and n. To set IFS to a newline, use IFS=$'\n'.
Second mistake: to set a variable to an array value, you need parentheses around the elements: array_of_lines=(foo bar).
This would work:
IFS=$'\n' array_of_lines=($(my_command))
But I recommend not to mess with IFS; instead, use the f ...

In zsh, the function search path ($fpath) defines a set of directories, which contain files that can be marked to be loaded automatically when the function they contain is needed for the first time.
Zsh has two modes of autoloading files: Zsh's native way and another mode that resembles ksh's autoloading. The latter is active if the KSH_AUTOLOAD option is ...

You can run bindkey with no arguments to get a list of existing bindings, eg:
# Enter vi mode
chopper:~> bindkey -v
# Search for history key bindings
chopper:~> bindkey | fgrep history
"^[OA" up-line-or-history
"^[OB" down-line-or-history
"^[[A" up-line-or-history
"^[[B" down-line-or-history
In emacs mode, the binding you want is ...

Check if the INTERACTIVE_COMMENTS option is set.
According to this page, "[...] in interactive shells with the INTERACTIVE_COMMENTS option set, [...] # causes that word and all the following characters up to a newline to be ignored."
According to the comments were added later, set -k does exactly the same thing.

First, separate zsh from the rest. It's not a matter of old vs modern shells: zsh behaves differently. The zsh designers decided to make it incompatible with traditional shells (Bourne, ksh, bash), but easier to use.
Second, it is far easier to use double quotes all the time than to remember when they are needed. They are needed most of the time, so you'll ...

Here is a non-exclusive list of what each file tends to contain:
Since .zshenv is always sourced, it often contains exported variables that should be available to other programs. For example, $PATH, $EDITOR, and $PAGER are often set in .zshenv. Also, you can set $ZDOTDIR in .zshenv to specify an alternative location for the rest of your zsh configuration.
...

You didn't specify which shell you are using, so let this be excuse to advertise zsh.
Yes, we do have more history for cd, namely cd -2, cd -4 etc. Very convenient is cd -TAB, especially with completion system and colors enabled:
This is what I have in .zshrc:
setopt AUTO_PUSHD
setopt PUSHD_MINUS
setopt CDABLE_VARS
zstyle ':completion:*:directory-stack' ...

Several forms of complex commands such as loops have alternate forms in zsh. These forms are mostly inspired by the C shell, which was fairly common when zsh was young but has now disappeared. These alternate forms act exactly like the normal forms, they're just a different syntax. They're slightly shorter, but less clear.
The standard form for the for ...

a | b connects STDOUT from a and STDIN from b just by using dup/dup2. Both commands are executed in parallel.
a =(b) replaces the argument to a with an temporary filename. b will be executed before a as the temporary file needs to be created before it can be passed to a
a <(b) replaces the argument to a with an named pipe. a and b run in parallel. This ...

It has insert and normal mode (the insert mode is default, and escape for normal mode) but no visual mode.
In bash: set -o vi You can run it at the command line for just this session or add it to your .bashrc file.
Many programs use readline for input, and you can make any of them use vi-style keybindings by setting up your .inputrc with
set editing-mode ...

cp a b && mv b c && rm a & is correct. & has lower precedence than &&. In fact & has lower precedence than anything other than ; and newline: & is in the same syntactic category as ;, the difference being that ; runs the command list in the foreground while & runs it in the background. You can test this for ...

Add to the following to ~/.inputrc:
# Press up-arrow for previous matching command
"\e[A":history-search-backward
# Press down-arrow for next matching command
"\e[B":history-search-forward
Explanation
~/.inputrc is the configuration file for GNU readline. Many shells, including bash and tcsh use readline for command line editing. The two lines above will ...

You cannot solve this through shebang directly, since shebang is purely static. What you could do is having some »least common multiplier« (from a shell perspective) in the shebang and re-execute your script with the right shell, if this LCM isn't zsh. In other words: Have your script executed by a shell found on all systems, test for a zsh-only feature ...