[Top][All Lists]

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

Re: Escaped percent sign in shell escape (bang) command (ed 1.16)

From: John Cowan
Subject: Re: Escaped percent sign in shell escape (bang) command (ed 1.16)
Date: Tue, 13 Jul 2021 11:49:18 -0400

The Posix standard says "Within the text of that shell command line, the
unescaped character '%' shall be replaced with the remembered pathname".
Now if "unescaped" means anything at all here, it means "not preceded by a
backslash", just like everywhere else in Posix.  So the current GNU
behavior is unequivocally wrong.

Both the GNU and BSD man pages say that escape sequences are not treated
specially in the "!" command, and this also seems to be wrong or at best
misleading.  The BSD behavior of "echo '\%' is to output "\%", which is
certainly not illegal.

But we must ask if it is the most useful behavior.  I contend that it is
not.  If you want to pass a '%' character to the shell, the obvious way to
do so is by writing '\%', just as the way to get '*' interpreted literally
in a regex is to write '\*'.  The BSD behavior is not only surprising, it
makes it impossible to send a simple '%' to the shell at all.  This is the
problem which escape sequences were designed to solve.

So I argue that the sequence '\%' in a '!' command should send '%' to the
shell without a backslash, and that the man page be fixed.  I further argue
that '\\' s

reply via email to

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