What about
STR1="This is a string" StrFix="$( echo "$STR1" | sed 's/[[:space:]]/,/g')" echo "$StrFix" **output** This,is,a,string
If there are several contiguous spaces in your line and that they should be reduced to 1 comma, change sed to
STR1="This is a string" StrFix="$( echo "$STR1" | sed 's/[[:space:]][[:space:]]*/,/g')" echo "$StrFix" **output** This,is,a,string
I use custom sed and therefore used `` [[: space:]] [[: space:]] * to indicate one or more "white-space" characters (including tabs, VT, maybe a few others). In a modern sed, I would expect to indicate one or more "white-space" characters (including tabs, VT, maybe a few others). In a modern sed, I would expect [[: space:]] + `to work the same.
shellter
source share