What is the purpose of cd ` (backtick)?
What you've typed is a backtick - it is the start of an instruction to bash to evaluate what you type as a command. The >
is displayed to indicate you are still entering the command on the next line.
If you close the backtick you'll find the whole command will run. E.g.
~$ cd `
> echo /var`
/var$
JohnC's answer already explains the backtick. But what you are also wondering about is the >
prompt. This a continuation prompt, and it is not only triggered by a backtick, but always when your shell clearly knows you're not done entering a command. The easiest example is putting an explicit line continuation \
at the end of an input line (which helps splitting long input):
$ echo \
> hallo
Note that just like PS1
controls the command prompt's look, you can also set PS2
to change the continuation prompt, e.g.
$ export PS2="(cont.) "
$ echo \
(cont.) hallo
There are many reasons for the continuation to occur. A single backtick is incomplete, but you could also enter something like
ls -l `which cp`
in a single line (side-note: It's recommended to use $(
and )
instead, since the parentheses make it obvious where the expansion starts and ends, while single backticks make it more difficult to see where one's missing. And nesting...). Other possible reasons for a continuation prompt:
- a missing
done
afterwhile
orfor
- a missing
fi
after anif
- a missing
esac
aftercase
- a missing closing parenthesis, e.g. in subshells
(cd $HOME; cat .bashrc)
- a missing command after piping
|
as well as conditional execution||
and&&
(not&
though, since that's just making the command running in background) - a missing closing quote (
'
or"
)
Curiously enough, a missing brace }
after a variable expansion ${
also causes a continuation prompt, but will fail due to the inserted space:
$ echo ${
> PS2}
bash: ${
PS2}: bad substitution
It means that your command is not complete yet. In fact, the character backtick, `
, is used to delimit an inline command.
Example:
cd /tmp # Go to /tmp
pwd # Prints the current working directory
ls `pwd` # Lists the content of the current working directory