I accidentally typed in cd ` into terminal today and terminal didstrange things.

It put a "> " signed on the next line followed by my cursor like it wanted some input. No matter what I entered continued to do the same thing until I terminated the command.

Out of curiosity what happened? Was this a bug or a feature?

  • When you do such a mistake, use Ctrl-C to break out of trouble. – cylgalad Sep 30 '15 at 10:32

Answered here already... essentially

Everything you type between backticks is evaluated (executed) by the shell before the main command

  • 1
    I had read that and tried typing commands to no effect. Your post made me think to try another backtick, which acted as in the other post. – yesennes Sep 30 '15 at 3:49

The effect you witnessed is due to the shell expecting another backtick. You get the same effect when you, for example, enter ( (or any other incomplete command) and press Return on the command line.

The prompt, >␣, that you got is the secondary prompt, as stored in $PS2. This prompt is used by the shell when more interactive input is needed to finally complete the command.

An example:

bash-4.4$ for i in {0..10..2}
> do
> printf 'Hello %d\n' "$i"
> done
Hello 0
Hello 2
Hello 4
Hello 6
Hello 8
Hello 10

bash-4.4$ is my primary prompt ($PS1), and I get the secondary prompt when pressing Return after {0..10..2} on the first line since the command typed in so far is not complete. I continue to get the secondary prompt on each line until I have completed the command by pressing Return after done (which completes the input of the for-loop to the shell).

The tertiary prompt ($PS3, usually #?␣) is used by the select keyword, while the quaternary1 prompt ($PS4, usually +␣) is used for tracing output when the shell xtrace option is set with set -x.

1 Yes, I had to look up that word.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.