Generating a JSON map containing shell variables named in a list
问题 My shell-fu is at a below-beginner level. I have a file that contains some lines that happen to be the names of environment variables. e.g. ENV_VAR_A ENV_VAR_B ... What I want to do is use this file to generate a JSON string containing the names and current values of the named variables using jq like this: jq -n --arg arg1 "$ENV_VAR_A" --arg arg2 "$ENV_VAR_B" '{ENV_VAR_A:$arg1,ENV_VAR_B:$arg2}' # if ENV_VAR_A=one and ENV_VAR_B=two then the preceding command would output # {"ENV_VAR_A":"one",