[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: Antonio Diaz Diaz
Subject: Re: Escaped percent sign in shell escape (bang) command (ed 1.16)
Date: Wed, 14 Jul 2021 16:32:49 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv: Gecko/20110420 SeaMonkey/2.0.14

John Cowan wrote:
The Posix standard says "Within the text of that shell command line, the
unescaped character '%' shall be replaced with the remembered pathname".

Which is what GNU ed does.

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.

What "current GNU behavior" are you talking about?

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.

And is also what GNU ed has done since 1994.

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 '\\' should send a single backslash to the shell, so
that you can write !echo '\\n" to get the output '\n'.

Not so agreed. Now you can write !printf '\n' to get the output '\n'.

$ printf '%s\n' 'r !printf "% modified on \n \%d\n" 23' ',n' Q | ed -s fil1
printf "fil1 modified on \n \%d\n" 23
1       fil1 modified on
2        \23

Best regards,

reply via email to

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