0

I have noticed a tendency in Unix shells and other languages like LaTeX, HTML to eliminate symmetric enclosing syntax.

By symmetric enclosing syntax, I mean that the opening and closing signs are the same, for example, shell single quote ', double quote " and backtick `, LaTeX $.

We are advised to replace symmetric enclosing syntax by asymmetric enclosing syntax, for example, write in shell $(ls) not `ls`, in LaTeX \(2+2\) not $2+2$.

Reasons for this change are the ease of interpretation for a human reader or a computer program (parser) and the problem of nesting.

The workaround for nesting quotes is usually to use double quotes at one level and single quotes at the other, but this does not work with three levels, for example echo "'"a"'", and also single and double quote differ with respect to parameter substitution so you can't use parameter substitution at both levels.

Is there a way to replace Unix shell single and double quotes by asymmetric constructs allowing nesting?

I have found $'' as an asymmetric alternative to single quotes but what for double quotes?

($"" does not work for this in zsh.)

Pierre ALBARÈDE
  • 413
  • 4
  • 10
  • `Is there a way...` you want an answer like: write your own shell that does that? `$"" does not work for this in zsh` No, `$""` is not for that, it's for translating messages. – KamilCuk Apr 23 '21 at 15:42
  • I would rather find something existing in any of the common shells like zsh, bash or to be convinced that what I am looking for is not useful. – Pierre ALBARÈDE Apr 23 '21 at 18:35

1 Answers1

1

Is there a way to replace Unix shell single and double quotes by asymmetric constructs allowing nesting?

Yes, write your own shell implementation that would support what you want. Existing shells do not support such thing. Pick an unambiguous sequence of characters to denote the quoting, so that it doesn't interfere with other shells and hopefully causes a syntax error when run with other shell implementations.

I have found $'' as an asymmetric alternative

$'' is an ANSI C quoted string and $"" is for locale translation. These are not alternatives to quoting.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111