0

I have a variable DEFAULT_SETTINGS which is collected via curl. I need to replace a substring of this variable before writing it to a file. How can I do this?

DEFAULT_SETTINGS=$(curl -H "Authorization: Bearer $AUTH_TOKEN" https://appserver/repositories/$GITHUB_REPOSITORY_NAME/default-settings)
# [REPLACE:APPLICATION_NAME]
echo "$DEFAULT_SETTINGS" > "$GITHUB_REPOSITORY_NAME/appsettings.json"

I understand I can echo it with sed but I want to echo it to the file?

  • What exactly needs to be replaced? I would have very different answers for editing arbitrary text versus editing a JSON object. – chepner Mar 29 '23 at 14:08
  • 1
    `sed` and `echo` both write to standard output by default, and so each can be used with output redirection in the same way. – chepner Mar 29 '23 at 14:08
  • Put the filter on the assignment. eg `default_setting=$(curl ... | sed ...)` – William Pursell Mar 29 '23 at 14:10

0 Answers0