Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does triple-single-quote mean in bash?

Tags:

bash

shell

I have seen lots of uses of single and double-quotes in bash, as well as backtick-quotes, but have never seen what follows. What is the meaning of the transcript below, which seems to show that triple-single-quoting is recognized as meaningful by bash and further seems to show that single quotes inside this thing also have special meaning, enabling interpolation? I have found no documentation of this.

$ Q=test
$ echo '$Q'                      # <== I know, this doesn't work...
$Q                               # <== ...and so it doesn't. 
$ echo '''$Q'''                  # <== Don't know what this could mean.
$Q                               # <== OK, nothing special?
$ echo ''' "$Q" '''              # <== Try a double-quote??
 "$Q"                            # <== Hmm... OK, nothing.
$ echo ''' '$Q' '''              # <== Try a single-quote?
 test                            # <== Wow, it did interpolate!?
$ echo '''                         
> '''                            # <== Continuation! Proving bash  
                                 #     thinks this is an opening 
                                 #     quote of some kind.
$ bash --version                 # <== FYI,  version info
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.
like image 620
user62177541 Avatar asked May 04 '19 02:05

user62177541


1 Answers

There is no “triple quote” ... for example ''' '$Q' ''' is the concatenation of several strings ... '', ' ', $Q, ' ' and ''. Consider each of the others in the same way.

like image 134
donkopotamus Avatar answered Oct 15 '22 03:10

donkopotamus