Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to best match $( ... ) in a string



On Fri, 1 Jun 2018 10:44:58 +0200
Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> the problem is possible quoting, e.g. $( echo \) ). Has anyone a
> pattern that would handle some sort of quoting?

In general, this isn't possible.  Apart from nested unquoted
$(...), which is also valid, the real killer is

echo $(case foo in
  foo) echo This does work
  ;;
  esac)

This required us to rewrite our internal parsing completely and we're
still shaking the odd bug out of the result.

If you ignore that case, it's possible character by character with
a bit of extra state for quotes, nested parentheses, etc. (as that's
what zsh did for two decades) but you're going to need some incredibly
sophisticated regular expression involving recursion to replace that.

pws



Messages sorted by: Reverse Date, Date, Thread, Author