bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Percent Signs in External Commands on Windows


From: David Millis
Subject: Re: [bug-gawk] Percent Signs in External Commands on Windows
Date: Thu, 12 Apr 2012 22:19:03 -0700 (PDT)

Addendum to the other email today...

--- On Thu, 4/12/12, Eli Zaretskii <address@hidden> wrote:

> > You protect your first and last quotes, buy _adding_
> > quotes whose sole purpose are to get eaten by CMD's stupid
> > but predictable heuristic.
> outer quotes are only removed if the whole command starts
> with a quote, which is not always what you want (think about
> protecting a wildcard).

If you thought the wget example was insufficiently loaded with questionable 
characters that might be subject to a hypothetical added round of globbing, 
here's something contrived to show how aloof CMD is...

Live shell prompt (bat works too):
c:\> ECHO hello world|gawk.exe -F \\s "{print gensub(/ll/, \"w\", \"\", $1) 
\"?\";}"
---
hewo?
---

cmd /c ... (same string, no quotes):
c:\> cmd /C ECHO hello world|gawk.exe -F \\s "{print gensub(/ll/, \"w\", \"\", 
$1) \"?\";}"
---
hewo?
---

cmd /c "..." (same string, plus added fodder quotes):
c:\> cmd /C "ECHO hello world|gawk.exe -F \\s "{print gensub(/ll/, \"w\", \"\", 
$1) \"?\";}""
---
hewo?
---
No effect on the content of the /C arg vs live prompt.
As the docs say, CMD doesn't do anything other than remove the two outermost 
quotes from the entire string. A user can safely add two syntactically 
irrelevant quotes to ensure whatever's within is undisturbed, and no additional 
globbing is incurred by this.

CMD's too stupid to get in the way by trying to be clever about /C.

The quirk batch files have is that they disagree with live prompts about how 
undefined %FOO% variables should be treated: blanked vs left as literals.

That's it. One system() route only needs quotes concatenated. The other needs 
percents doubled throughout and sane use of ENVIRON[]. Special characters 
aren't any better preserved in a temporary batch file. It just makes percents 
vulnerable.


David Millis




reply via email to

[Prev in Thread] Current Thread [Next in Thread]