-1

A simple function receive two arguments and add and ,then print them.

function myprint(){ echo "$1 and $2";}

It works.

myprint  xx  yy
xx and yy

It is a string,bash parse it separately.

"myprint  xx  yy"
bash: myprint  xx  yy: command not found

Why double double quotes make string run as function?

""myprint  xx  yy""
xx and yy
scrapy
  • 163
  • 1
  • 2
  • 12

1 Answers1

3

Your "double double quotes" are in fact not nested. Two times a double quote is opened and closed right away.

""myprint  xx  yy""
^^                  this is one pair of quotes with empty content
                 ^^ this is anther pair with empty content
  ^^^^^^^^^^^^^^^   this is not quoted at all

In effect ""myprint is the command named: the empty string concatenated with "myprint", this resolves to the myprint function; and the last argument is the string "yy" concatenated with the empty string.

So you get unquoted myprint xx yy. The whole original command behaves as such.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202