Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What occurs when you type quotation mark " in shell terminal

Tags:

shell

unix

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.

like image 645
Cloud_iceberg Avatar asked May 21 '13 20:05

Cloud_iceberg


People also ask

What does quoting mean on a shell command line?

Quoting is used to prevent the shell from acting on and expanding its meta-characters. The quoting causes the shell to ignore the special meaning of the character, so that the character gets passed unchanged to a command as part of a command argument.

What do single quotes do in bash?

Single quotes can be used around text to prevent the shell from interpreting any special characters. Dollar signs, spaces, ampersands, asterisks and other special characters are all ignored when enclosed within single quotes. echo 'All sorts of things are ignored in single quotes, like $ & * ; |.

How do you put quotes in a shell script?

Enclosing characters in single quotation marks (') holds onto the literal value of each character within the quotes. In simpler words, the shell will interpret the enclosed text within single quotes literally and will not interpolate anything including variables, backticks, certain \ escapes, etc.

What do quotation marks mean in Linux?

Quotes are used at the command line to cause certain special characters to be ignored. Quotes allow characters to be used like ampersands as part of a sentence and multiple words are treated as a single argument for commands.


1 Answers

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.

like image 109
hexacyanide Avatar answered Sep 28 '22 09:09

hexacyanide