mles mles - 4 months ago 8x
Bash Question

Prevent sed from creating a temporary file

I'm injecting a proxy variable into a shell script. I have to escape the string as there is a space in between.

sed -i -e 's#UseConcMarkSweepGC#UseConcMarkSweepGC $PROXY_ARGS#g' ${TEST_HOME}/bin/

Now this is always generating another file ith
at the end, so I end up with
. Both are the same. Currently I'm doing


right after
which is working fine. I'm wondering if there is a way to not generate a temporary file at all? I can't remove the
as I'm getting the error
sed: -i may not be used with stdin


This is because of the order you are placing the flags, if you are under a non-GNU sed that requires -i to have an argument:

sed -i -e '...'
#   ^^ ^^
#   |   |
#   flag|
#       |
#       value for it

Like this, sed understands -e as the extension of the backup file to create.

Instead, say:

sed -e -i '...'

Or just be explicit about the extension and set it to null, so that no backup file is created:

sed -i '' -e '...'

See more information in sed: -i may not be used with stdin on Mac OS X.