Subject: sed -iSUFFIX/--in-place=SUFFIX doesn't work for absolute paths if the input file(s) is not in the current directory.

From: Sebastian Carlos <[email-masked]>
Date: Fri, 2 Jun 2023 11:30:25 +0200

Environment: Arch, GNU sed version 4.9, Bash 5.1.16

Given the following:

$ mkdir test
$ cat << 'EOF' > test/shopping-list
- GNUtella (1 jar)
- GNUpcakes (12 pieces)
- GNUsabi (100 g)
- Bash potatoes (2 kg)
- Sed-a cheese (200 g)
EOF

Attempting backup to an absolute path fails with an obscure error:

$ sed --in-place=/var/tmp/*.bak 's/1 jar/2 jars/' test/shopping-list
sed: cannot rename test/shopping-list: No such file or directory

But it works if the input file is in the current directory:

$ cd test
$ sed --in-place=/var/tmp/*.bak 's/1 jar/2 jars/' shopping-list
$ diff /var/tmp/shopping-list.bak shopping-list
1c1
< - GNUtella (1 jar)
---
> - GNUtella (2 jars)

Thanks!