0

So, I have some scripts that are used when I start my server.

I can access and edit some, but there are others that I can't access nor edit.

In my last script, I have the following lines :

JAVA_OPTIONS="${JAVA_OPTIONS} -Denv.name=DEV -Dperf.active=true -DUseSunHttpHandler=true"
export JAVA_OPTIONS

In order to add a few options. But there are some option in JAVA_OPTIONS that I want to remove (it's added in a .sh I don't have access to)

This is the option I want to remove :

-Djava.endorsed.dirs=/produits/weblogic/jdk/jdk1.8.0_45/jre/lib/endorsed:/produits/weblogic/weblogic-12.1.3/wlserver/../oracle_common/modules/endorsed -da

How can I achieve that by editing my last script ?

Ellone
  • 3,644
  • 12
  • 40
  • 72
  • This general approach (trying to put multiple arguments inside a string variable) is innately buggy and shouldn't be used -- yes, it *commonly is* used in the Java world, but I'd argue that that's because Java people don't grok bash :); it restricts arguments' possible values, preventing whitespace, or anything that needs quotes or other syntax unless used in conjunction with `eval`, which adds its own problems -- see [BashFAQ #50](http://mywiki.wooledge.org/BashFAQ/050) describing the bugs it causes and available alternatives; and [BashFAQ #48](http://mywiki.wooledge.org/BashFAQ/048) re eval – Charles Duffy Aug 09 '18 at 12:33
  • Getting away from structural discussions and towards the question, though: by "by editing" you mean you have access to edit the script? What's holding you from just going in with an interactive editor, then? – Charles Duffy Aug 09 '18 at 12:35
  • ...similarly, we have a good set of duplicates already present on site covering removing a substring matching a pattern -- explaining why they can't be used would make the question stronger. – Charles Duffy Aug 09 '18 at 12:35
  • Like this one: bash can do replacement itself, sed is another option https://stackoverflow.com/questions/13710806/how-to-replace-placeholder-character-or-word-in-variable-with-value-from-another – Lesiak Aug 09 '18 at 12:36
  • Similarly, [how to replace a string in multiple files linux command line](https://stackoverflow.com/questions/11392478/how-to-replace-a-string-in-multiple-files-in-linux-command-line) is another question that looks like an applicable duplicate. I'm closing this as duplicative for now -- if you edit the question to distinguish it (explaining as part of the question *why* the purported duplicates don't work when applied), @-notice me and I'll reopen. – Charles Duffy Aug 09 '18 at 12:37
  • BTW, [BashFAQ #21](https://mywiki.wooledge.org/BashFAQ/021) - *How can I replace a string with another string in a variable, a stream, a file, or in all the files in a directory?* - is likely to be broadly applicable. – Charles Duffy Aug 09 '18 at 12:39

0 Answers0