2

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/test.sh

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

rm test.sh-e

right after sed 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 -e as I'm getting the error sed: -i may not be used with stdin.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
mles
  • 4,534
  • 10
  • 54
  • 94

1 Answers1

9

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.

Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598