This is a question regards to sed on Mac, which requires a zero-length string for in-place replacement without backup files.
#!/usr/bin/env bash -x
SEDOPT='-i "" '
echo $SEDOPT
sed $SEDOPT -e "s/a/a/g" filename.txt
sed "$SEDOPT" -e "s/a/a/g" filename.txt
sed -i "" -e "s/a/a/g" filename.txt
If you execute the above commands, you will get the output like
1|+ SEDOPT='-i "" '
2|+ echo -i '""'
3|-i ""
4|+ sed -i '""' -e s/a/a/g filename.txt
5|+ sed '-i "" ' -e s/a/a/g filename.txt
6|+ sed -i '' -e s/a/a/g filename.txt
I'm setting up a sed option variable SEDOPT
, that will be changed depends distro.
Can someone help me on make the output of line 4 and 5 behave like line 6? Thank you.