Reputation: 75
I have been searching the web for this but I can't understand what the unix shell terminal is doing when you just type a quotation mark "
$ "
and it gives you something like that
>
where you can enter text and probably commands. Then if you enter again a single quotation mark character " it will quit the > prompt and go back to the regular $ prompt.
Upvotes: 6
Views: 7664
Reputation: 6764
It's showing you that it's still treating it as one command. This let's you format longer commands over a number of lines for legibility.
AFAIK, parentheses or backslashes will give you the same feature in most shells.
EDIT: +1 on Charles Duffy's comment; just to further expand on the differences between the three I mentioned above (I didn't realise, so might be useful to point them out). In a Bash shell (OSX):
Using quotation marks, as Charles Duffy mentioned, allow you to put your argument over multiple lines. The new line character becomes part of your argument however, e.g.:
$ touch "hello
> world"
Will give you a filename that has a newline control character as part of it's name.
Adding a backslash to the end of one line will enter multi-line mode, but will continue to add onto the same command, e.g.:
$ touch hello \
> world
Will give the same as touch hello world
(i.e., passing two parameters to touch & so creating two files hello
and world
).
Parentheses will let you chain commands together, so:
$ (touch hello
> world)
Will execute touch hello
and then world
, i.e. it's the equivalent of doing touch hello; world
on a single line. (probably giving -bash: world: command not found
for the world command).
So quotation marks will enter multi-line input & also preserve any new line characters that you input as part of that.
Upvotes: 1
Reputation: 91799
This is what the Bash manual states:
3.1.2.3 Double Quotes
Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘
’, ‘\’, and, when history expansion is enabled, ‘!’. The characters ‘$’ and ‘
’ retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ‘!’ appearing in double quotes is escaped using a backslash. The backslash preceding the ‘!’ is not removed.
When you type a single double quote, Bash is just waiting for you to finish with the second double quote.
Upvotes: 2
Reputation: 62489
"
on a bash
command line starts (or finishes, if there was another one earlier) a double-quoted string (rather obvious naming convention). '
starts a single-quoted string. bash
expects these to occur in pairs, and the entire string enclosed by a pair of quotes of either type is subject to different rules regarding how things are expanded and/or combined within them. Since you are typing only a single "
, bash
continues reading more input, waiting for you to put in the closing quote before it decides what it thinks you're asking it to do.
Both types of quotes are useful for naming files, commands, arguments, etc. that would otherwise be split at a space or other character. Single quotes also affect how variables are expanded within the string. Those are the most common uses, but there are others. Read man bash
for more information.
Upvotes: 2
Reputation: 195229
like hexacyanide said, it is waiting for you to complete your command.
Double quote expands shell variables. So you could build your command with variables. I would add an example:
kent$ x=eq
kent$ "s$x" 3
1
2
3
Upvotes: 0