3 ms·
Why not use bash's printf %q? string=$(printf ' %q' "${array[@]}")
by databasher 7y ago
Why not use bash's printf %q?
string=$(printf ' %q' "${array[@]}")
- jwilk 7y agoIn Bash ≥ 4.4, you can also use parameter transformations: function quote() { echo "${@@Q}" } (In both cases, the generated output is understood bash, but not necessarily by other POSIX-compliant shells.)