Skip to content

Instantly share code, notes, and snippets.

@thejimnicholson
Created October 4, 2019 21:31
Show Gist options
  • Save thejimnicholson/1c319a04eca180fe5262cab078f77779 to your computer and use it in GitHub Desktop.
Save thejimnicholson/1c319a04eca180fe5262cab078f77779 to your computer and use it in GitHub Desktop.
Create JSON in bash using heredocs
#!/usr/bin/env bash
var1='value of var1'
var2='value of var2'
read -r -d '' block <<-END
{
"var1": "${var1}",
"var2": "${var2}"
}
END
block2=$(cat <<_EOF2_
{
"var1": "${var1}",
"var2": "${var2}"
}
_EOF2_
)
echo "$block"
echo $block2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment