[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: |
Andrew L. Moore |
Subject: |
Re: Escaped percent sign in shell escape (bang) command (ed 1.16) |
Date: |
Sat, 8 Jan 2022 20:36:03 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1 |
On 1/8/22 17:50, Antonio Diaz Diaz wrote:
$ printf '%s\n' 'r !date +"% modified on \%F"' ',p' Q | ed -s fil1
date +"fil1 modified on %F"
fil1 modified on 2022-01-08
$ ed -V
GNU ed 1.18-rc1
There are a couple of issues that I'd encourage you to explore:
1) Though POSIX doesn't specify ed's behavior when commands are read
from a pipe, historically, errors do not cause ed to exit.
Nonetheless, errors should be reported, even with option -s, which
POSIX is very explicit about, i.e., from
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html:
-s
Suppress the writing of byte counts by e, E, r, and
w commands and of the '!' prompt after a !command.
In your example above, if the file `fil1' does not exist, an error
is reported without option -s. So an error should also be reported
with option -s.
For what it's worth, Illumos ed also suppresses error reporting
with option -s. But Illumos ed also prints a backslash and fails
to assign `fil1' as the default filename.
2) Backslash-escape processing of filenames should be restricted to a
leading exclamation mark, if any, or eliminated altogether. The
intent of backslash escape processing was to support reading files
whose names begin with an exclamation mark without forking a shell.
But systemd, in particular, likes to generate files and directories
with backslashes (see, for example,
https://www.freedesktop.org/software/systemd/man/systemd-escape.html#).
This is problematic for
commands like `systemctl edit' if your editor is set to ed.
To illustrate the problem:
ed -p '*' '\x2dhyphen\x2dprefixed\x2dfile'
\x2dhyphen\x2dprefixed\x2dfile: No such file or directory
*f
x2dhyphenx2dprefixedx2dfile <-- backslashes have been stripped!