2

If I type for example

grep 'needle
>

I get sent to a mysterious > prompt from which ctrl-C (or restarting the terminal) is seemingly the only escape.

  1. What is this prompt?
  2. Why doesn't it terminate when I enter ctrl-Z?
  3. Why isn't it better designed to detect trapped newbies? Sure, maybe in some ridiculously contrived edge case there would be a reason to open this > prompt and then input something like "quit\nexit\nhelp\nCTRL-Z\nlogout\n", but if the user starts entering those things, Ubuntu should at least issue a helpful response message (e.g., "Are you trying to get out of this prompt? If so use CTRL-C. If not, ignore this message.") that wouldn't interfere with whatever weird purpose the prompt serves.

3 Answers 3

2

This is because you opened a quote (" or ') so the shell assumes that the command in continuing, what is indicated by this > character. So until the closing quote you will get the > prompt to finish the started command.

This is when you want to echo something with newline in it, for example:

user@host:~$ echo "this
> is a text
> with multiple
> newlines"

outputs:

this
is a text
with multiple
newlines

To abort you can also hit Ctrl+c.

1

There is nothing mysterious. That prompt (>) is suggesting you that the shell is waiting for second quote ' and a filename to finish your command. If you want to search for 'needle then use:

grep \'needle filename

And Control+Z is used for suspending a job, but you don't have any job started only by entering grep 'needle.

And, at the third point, I would say that this will sound ridiculous for users who really work with the terminal. Plus: how do you thing that the terminal could detect if someone is newbie or not? And what if someone really wants to enter those strings: "quit, exit, help, logout"?

See also:

7
  • Ah I suspected as much but When I do $grep 'needle >' I am tranferred to another mysterious prompt with NO > or $ or anything. This is of course because that's where grep 'needle' would send me, and what I really need to do is grep 'needle' * (why is grep so badly designed in that sense? but that's another issue for another post)
    – Anonymous
    Oct 23, 2013 at 12:29
  • 1
    When you type grep 'needle >' the command grep waits for input from stdin. So everything you type. When you type needle > then, it will be grepped and printed... Can be very strange to shell beginners =)
    – chaos
    Oct 23, 2013 at 12:39
  • @Anonymous See also man grep. This time, when you use grep 'needle >' type ` blabla needle > blabla` to see what's happening. And this time yes, you have a job that can be stopped, so you can use Ctrl+Z. See also my new edits at the answer. Oct 23, 2013 at 13:00
  • Thanks for all the illuminating help. So as a side topic, why does the > prompt ignore CTRL-Z? I'm having trouble picturing any reason why it apparently intercepts the signal and ignores it. Why else would the user be pressing CTRL-Z if not to kill whatever is going on (the > prompt)?
    – Anonymous
    Oct 23, 2013 at 21:22
  • @Anonymous Have you looked over: What's different between Ctrl+Z and Ctrl+C in Unix command line?. Is not clear yet for you that Ctrl+Z doesn't kill anything? It only suspend a process for later resumption. Only Ctrl+C can kill whatever you are doing in terminal. Oct 24, 2013 at 6:03
0

The prompt is just the standard input. the ' character is interpreted as 'start of a string' so it excepts for a closing '. when you press return before the closing ' it is interpreted as a newline. you can continue writing what you want. when you type a ' and press enter it gets the whole string you wrote

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .