0

I need to append the path /opt/dell/dcc of an application outside of the default path statement in /etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/dell/dcc"

The problem is the append must be inside the closing double quote of the pair which encases the path.

0

Although this example applies to editing a path in a specific file, many directive values in config files requiring modification with sed can be encased between a pair of quotes. Feeling that the solution could be of broad interest, I've shared it below:

sed 's#"$#:/opt/dell/dcc"#' /etc/environment

Screenshot of proof solution works as described

The benefit of matching on the final quote is that it ensures even if the path changes in future, this sed expression will still work correctly appending the custom path on the end of it before the closing double quote.

The above sed expression is tested and known to work correctly, but others might have a more elegant way to achieve the same result; please feel free to share them here.

Don't forget to add -i switch to make changes persistent after testing-

  • 2
    It would be better to copy&paste the text from the screenshot as text. BTW: If you use other separators in your sed command you don't need to escape the slashes, e.g. sed 's#"$#:/opt/dell/dcc"#' – Bodo Jun 5 at 16:56
  • D'oh! of course! Thanks for improving the solution @Bodo ! Just incorporated your feedback into the solution- – F1Linux Jun 5 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.