공부
[Shell]join string array
승가비
2022. 6. 20. 00:13
728x90
#!/bin/bash
foo=('foo bar' 'foo baz' 'bar baz')
bar=$(printf ",%s" "${foo[@]}")
bar=${bar:1}
echo $bar
https://stackoverflow.com/questions/1527049/how-can-i-join-elements-of-an-array-in-bash
How can I join elements of an array in Bash?
If I have an array like this in Bash: FOO=( a b c ) How do I join the elements with commas? For example, producing a,b,c.
stackoverflow.com
728x90