I need a single-line unix file that displays the current runtime as a JSON structure, for example: {"env-var": "env-value", ... etc.}}
This kind of work:
(echo "{"; printenv | sed 's/\"/\\\"/g' | sed -n 's|\(.*\)=\(.*\)|"\1"="\2"|p' | grep -v '^$' | paste -s -d"," -; echo "}")
but it has some extra lines, and I think this will not work if the values ββor environment variables have '=' characters or new lines in them.
Would prefer pure bash / sh, but compact one-line python / perl / ruby ββ/ etc would also be appreciated.
json environment-variables jq
Constance eustace
source share