Bug 188535 - ed(1): ed/red - incorrectly sets current address upon removing last line
Summary: ed(1): ed/red - incorrectly sets current address upon removing last line
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-12 22:40 UTC by Volodymyr Kostyrko
Modified: 2017-12-31 22:27 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volodymyr Kostyrko 2014-04-12 22:40:02 UTC
Let's have some file:

  echo xxx > some_file
  echo yyy >> some_file

Now let's try to edit it with ed, lines starting from '>' are manual input:

> ed some_file
  8
> H
> =
  2
> g/yyy/d
> =
  2
> g/xxx/d
> =
  0
> g/zzz/d
  ?
  invalid address

When last line is removed from file current address is changed from 1 to
0 making all subsequent range addressing to fail. This violates the man page:

    Since the g (global) command masks any errors from failed searches and
    substitutions, it can be used to perform conditional operations in
    scripts; --

What I mean is that actually using g (global) is not fully safe. Imagine
I have a number of key fingerprints and I want to create a simple script
to remove them from 'known_hosts' throughout all of my machines. There
are a lot of fingerprints but each known_hosts file can contain only a
few of them thus script may fail when file is running out of lines.
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:39 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped