Skip to content

Commit c35ac25

Browse files
authored
ed: e! should not set filename (briandfoy#919)
* I hadn't tested this scenario before * First I start ed with a file a.c * The command "e !ifconfig" then replaces the buffer with the output of ifconfig * Listing current filename with "f" command after this should still show "a.c" (this is how GNU and OpenBSD versions behave) * The directory check should not happen for "e !..." case
1 parent a67d122 commit c35ac25

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

bin/ed

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ my $NO_QUESTIONS_MODE = 0;
105105
my $PRINT_NUM = 1;
106106
my $PRINT_BIN = 2;
107107

108-
our $VERSION = '0.25';
108+
our $VERSION = '0.26';
109109

110110
my @ESC = (
111111
'\\000', '\\001', '\\002', '\\003', '\\004', '\\005', '\\006', '\\a',
@@ -706,9 +706,15 @@ sub edEdit {
706706
}
707707
}
708708

709+
my $do_pipe = 0;
709710
if (defined $args[0]) {
710711
return E_FNAME unless (length $args[0]);
711-
$filename = $RememberedFilename = $args[0];
712+
if ($args[0] =~ s/\A\!//) {
713+
$do_pipe = 1;
714+
} else {
715+
$RememberedFilename = $args[0];
716+
}
717+
$filename = $args[0];
712718
} elsif (defined $RememberedFilename) {
713719
$filename = $RememberedFilename;
714720
} else {
@@ -717,13 +723,13 @@ sub edEdit {
717723
return;
718724
}
719725

720-
if (-d $filename) {
721-
warn "$filename: is a directory\n";
722-
return E_READ;
723-
}
724-
if ($filename =~ s/\A\!//) {
726+
if ($do_pipe) {
725727
return unless (open $fh, "$filename |"); # no error
726728
} else {
729+
if (-d $filename) {
730+
warn "$filename: is a directory\n";
731+
return E_READ;
732+
}
727733
unless (open $fh, '<', $filename) {
728734
warn "$filename: $!\n";
729735
return E_OPEN;

0 commit comments

Comments
 (0)