GNU bug report logs - #71682
sed -i '' returns error but still modify target file

Previous Next

Package: sed;

Reported by: Renato Botelho <garga <at> FreeBSD.org>

Date: Thu, 20 Jun 2024 18:23:01 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Renato Botelho <garga <at> FreeBSD.org>
To: 71682 <at> debbugs.gnu.org
Subject: bug#71682: sed -i '' returns error but still modify target file
Date: Thu, 20 Jun 2024 15:00:27 -0300
I'm writing a script that needs to run with both GNU and BSD sed 
implementations.  I know GNU sed accepts -i without any parameter while 
in BSD implementation it's mandatory.  I also know that if I use -i'' 
without spaces between -i and '' it works on both implementations and my 
problem is solved.

But I believe the behavior of GNU sed when there is a space between -i 
and '' is not correct.  It prints an error message and returns code 2 
but it still modifies the file.  Here is an example:

$ echo abcd > /tmp/f
$ sed -i '' -e 's/abcd/dcba/' /tmp/f
sed: can't read : No such file or directory
$ echo $?
2
$ cat /tmp/f
dcba

-- 
Renato Botelho





This bug report was last modified 1 year and 58 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.