bug-ed
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-ed] Not failing on no match.


From: Moore Andrew L.
Subject: [Bug-ed] Not failing on no match.
Date: Wed, 9 Mar 2011 16:25:48 -0800

Steve,
For the record, a belated reply to your question: how can ed(1) mask an error 
from a failed search 
<http://lists.gnu.org/archive/html/bug-ed/2008-09/msg00000.html>.

The "documented" way is to use the global command:
g/string/

In the context of scripting, ed(1) is documented to abort on errors.  
Historically, though, errors are masked when read via a pipe.  For example:

$ cat o.tmp
hello
world
$ cat o.ed
1,$s/foo/bar/
1,$s/hello/bye/
wq o2.tmp
$ ed - o.tmp <o.ed
?
$ cat o2.tmp
cat: o2.tmp: No such file or directory
$ cat o.ed | ed - o.tmp
?
$ echo $?
2
$ cat o2.tmp
bye
world
$

If it is important that ed(1) exit status also be zero, then the script could 
be written as:

$ cat o2.ed
g/foo/s//bar/
g/hello/s//bye/
wq o2.tmp
$ rm o2.tmp
$ ed - o.tmp <o2.ed
$ echo $?
$ cat o2.tmp
bye
world
$





reply via email to

[Prev in Thread] Current Thread [Next in Thread]