Ubuntu – “cd `” (backtick) command results in “>”, why and how to exit it

bashcommand line

When I type

cd `

into a terminal, then I get this


Even ls or cd is not working. Attempting to run such a command on the > prompt just gives another > prompt.

Please explain the meaning of the above command. And how do I exit it?

Best Answer

  • Backticks work in pairs. Bash is waiting for you to provide another backtick to complete the command/expression.

    > is simply a prompt for newline which is determined by the value of PS2 generally defined in .bashrc.

    Whenever you hit Enter (if the command/expression is incomplete, i.e. backtick isn't closed), bash expects you to complete the command/expression either in one line or multiple lines. For example, you want to evaluate value of 'a' using expr. You can do

    $ a=`
    > expr 1 + 3`

    will be interpreted as

    $ a=`expr 1 + 3`

    So, if you want to run some command either complete the required expression or if there is no command/expression required in between backticks, refrain from using that. Another way is to use Ctrl+C, but that would be a Keyboard Interrupt and will make your command to terminate immediately.

    To read more about backticks, read these questions on U&L: Understanding backtick and What does ` (backquote/backtick) mean in commands?