[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How is ${x:-"} parsed?
From: |
Eli Schwartz |
Subject: |
Re: How is ${x:-"} parsed? |
Date: |
Sun, 9 May 2021 16:56:56 -0400 |
On 5/9/21 4:48 PM, Peng Yu wrote:
> I see the following command is expecting something. I don't quite
> understand how it is parsed.
>
> $ echo "${x:-"}"
$ echo "${x:-"}"}"
}
You've successfully quoted the }, even if you didn't *mean* to, now you
need to end the ${
>
> Is the second double quote expecting another double quote to pair it?
> If so, how to pair it?
>
> Alternatively, wouldn't it better to just print the error at the
> second double quote since it should follow the dash character?
Many programming language parsers have sub-optimal diagnostics when
tripping over a grammatical syntax error and being unable to backtrack
to the most likely place where the user made a mistake.
bash: unexpected EOF while looking for matching `}'
"unexpected EOF" while trying to find some terminating character and
searching the *entire* file for it, is a pretty common error message
here and in other languages.
The most important thing to note is that:
- a mistake was made
- the beginning of the error relates to some use of {
--
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User
OpenPGP_signature
Description: OpenPGP digital signature