Bug 188535

Summary: ed(1): ed/red - incorrectly sets current address upon removing last line
Product: Base System Reporter: Volodymyr Kostyrko <arcade>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

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