0

I have a template file like this:

export const environment = {
  api: {
    url: '$API_URL',
    key: '$API_KEY',
  }
}

and I was trying to replace the actual placeholder values like this:

sed 's/$\([A-Z_]*\)/$(\1)/g' ./input.ts ./output.ts

So I wanted it to replace the placeholders with the actual values of the environment variables but when I run the above script I get:

export const environment = {
  api: {
    url: '$(API_URL)',
    key: '$(API_KEY)'
  }
}

So given these vars:

export API_URL=someurl
export API_KEY=key

I would expect the output to be:

export const environment = {
  api: {
    url: 'someurl',
    key: 'key'
  }
}

I can get this working with explicitly naming the variables:

sed -e 's|$API_URL|'$API_URL'|g
        s|$API_KEY|'$API_KEY'|g
        ./in.ts > ./out.ts

But is there a way to do this dynamically?

  • 2
  • they are brought in from an external program. It is an azure pipeline – dagda1 Feb 25 at 13:55
  • I have updated the question, please let me know if there is anything else I can do – dagda1 Feb 25 at 14:09
  • it is part of the output, I just want the $API_** placeholders replaced with the actual values of an environment variable that is the exact same name – dagda1 Feb 25 at 14:14
  • 1
    I have updated the question – dagda1 Feb 25 at 14:14

Your Answer

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

Browse other questions tagged or ask your own question.