PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 22, 2022

[FIXED] How to use curl to post a file, substituting env variables

 August 22, 2022     bash, curl, environment-variables, json     No comments   

Issue

How can I use curl and/or bash to post a file, substituting env variables.

Lets say I have test.json like so (which I can edit the format of):

{
  "name": "'"$NAME_VAR"'"
}

how can I post this file via curl, while substituting any env variable?

Example curl of posting a test.json file without substitutions:

curl -X POST -H 'Content-Type: application/json' --data-binary @test.json http://test-server/some/path

Solution

This seems like an XY Problem. Even if it isn't the question is underspecified. Does the solution have to support arbitrary var names or are they known apriori? Can the values contain quote marks that need to be properly escaped when interpolated into the JSON text? Why does the JSON text contain this unusual quoting:

"name": "'"$NAME_VAR"'"

If that can be changed to a single double-quote on each side of the env var name, and the env var value doesn't contain quotes, then the envsubst command is the simplest solution.



Answered By - Kurtis Rader
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing