0

I have a file such as this, which I am wanting to manipulate with sed.

// file.js
return foo.quux();

Running the following:

$ sed -i "s/foo\.(?!bar|baz)/qux\./g" file.js

Expected the file to be replaced such as:

// file.js
return qux.quux();

But bash keeps telling me:

bash: !bar: event not found

Rewrote as:

$ sed -i "s/foo\.(?'!'bar|baz)/qux\./g" file.js

But bash still wants to use the exclamation point for it's own purposes:

bash: !: event not found

Anyone have any tips on how to craft the exclusion for sed without bash trying to get involved?

jerome
  • 4,809
  • 13
  • 53
  • 70
  • That's history expansion messing you up -- it's an interactive feature not relevant for scripting (turned off during script execution). You can turn it off in your interactive shell too. Note that questions about *interactive* shell use, vs script development, are often a better fit for [unix.se] than StackOverflow. – Charles Duffy Aug 02 '18 at 18:38
  • Cool. This is starting to turn into enough commands it should be in a script anyway, so this question of mine is becoming irrelevant. – jerome Aug 02 '18 at 19:10

0 Answers0