-1
attribute=( a b c )

I need the array to be held in a variable and show like so:

"a" , "b" , "c"
  • Is this what you're looking for? https://stackoverflow.com/questions/49184557/convert-bash-array-to-json-array-and-insert-to-file-using-jq – Ole Jun 10 '21 at 12:31
  • Please c.f. [this guide](https://stackoverflow.com/help/asking) to asking a question well. http://idownvotedbecau.se/noattempt/ – Paul Hodges Jun 10 '21 at 15:59

1 Answers1

0

I suspect this is an XY Problem and you should really be asking about what you want as an end result rather than this micro-issue, but to answer the question you asked -

$: for a in "${attribute[@]}"; do str+="\"$a\" , ";done; str="${str% , }"
$: echo "[$str]"
["a" , "b" , "c"]

For the record, this is probably a bad idea.
Please consider editing your OP to discuss what you want to accomplish and what you have tried. Someone can almost certainly give you a better, safer, smarter solution.

Paul Hodges
  • 13,382
  • 1
  • 17
  • 36