Skip to main content
edited tags
Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
2
terdon
  • 252.3k
  • 69
  • 480
  • 718
Post Closed as "Duplicate" by muru bash
Source Link

Use string substitution to combine array?

I'm trying to use string substitution to combine an array. Output:

a,b,c

The below works, but isn't there a way to do with without piping?

#!/bin/bash

words=(a b c)

echo "${words[@]}" | sed 's/ /,/g'

I've tried this, which doesn't work.

echo "${words[@]// /,/}"