0

The following script

jq -r '.[] | $(echo .key | awk -v stg="$STAGE" '{  gsub("/"stg"/COMMON/", "", $0); gsub("/", "_", $0); print $0 })' + "=\"" + (.value|tostring) + "\""' tmp_common_params > tmp_common_params_cleaned

is giving error though

$(echo .key | awk -v stg="$STAGE" '{  gsub("/"stg"/COMMON/", "", $0); gsub("/", "_", $0); print $0 })

works individually

bash: syntax error near unexpected token `('
Walter A
  • 19,067
  • 2
  • 23
  • 43
  • https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash – KamilCuk May 23 '20 at 13:01
  • Even in the expression that 'works' I can see only one single quote (`'`). –  May 23 '20 at 13:06
  • hey not understanding can you explain – priyanshu kumar May 23 '20 at 13:20
  • Can you show the value of `$STAGE` and what you want to find with `echo .key | awk -v stg="$STAGE" '{ gsub("/"stg"/COMMON/", "", $0); gsub("/", "_", $0); print $0 }` ? I think this can be replaced by a very simple command, avoiding mistakes ith single quotes. – Walter A May 24 '20 at 08:45

1 Answers1

1

You are missing one ' at the end of this line, right after the last curly bracket and before the last parentheses:

> $(echo .key | awk -v stg="$STAGE" '{  gsub("/"stg"/COMMON/", "", $0); gsub("/", "_", $0); print $0 })

Try adding it and test again.

Also, you may find useful this tool for that kind of debugging: https://www.shellcheck.net/

mtnezm
  • 1,009
  • 1
  • 7
  • 19