ed: Add support for ! in w command

When the file name begins with ! then the addressed buffer content is
piped to the name of the file that is considered a command that is
executed in a shell.
This commit is contained in:
Heiko Berges 2023-09-21 14:56:58 +02:00 committed by Roberto E. Vargas Caballero
parent 53040766d1
commit 0b4c2ceb2f
1 changed files with 8 additions and 2 deletions

10
ed.c
View File

@ -626,8 +626,14 @@ dowrite(const char *fname, int trunc)
size_t bytecount = 0;
int i, line;
if (!(fp = fopen(fname, (trunc) ? "w" : "a")))
error("input/output error");
if(fname[0] == '!') {
fname++;
if((fp = popen(fname, "r")) == NULL)
error("Bad Exec");
} else {
if ((fp = fopen(fname, "r")) == NULL)
error("cannot open input file");
}
line = curln;
for (i = line1; i <= line2; ++i) {