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.
Agreed.
So I argue that the sequence '\%' in a '!' command should send '%' to the shell without a backslash, and that the man page be fixed.
Agreed.
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, Antonio.