3

How to simply combine field separated by a slash ?

LIST=("a" "b" "c")
STRING=???

echo $STRING
a/b/c

Please someone help? Thank you.

codeforester
  • 39,467
  • 16
  • 112
  • 140
Sat Net
  • 117
  • 2
  • 8

1 Answers1

3

In BASH you can do:

list=("a" "b" "c")
printf -v str "%s/" "${list[@]}"
str="${str%/}"

Check output:

echo "$str"
a/b/c

Avoid all CAPS variables in BASH.

Alternatively using IFS:

str=$(IFS=/; echo "${list[*]}")
anubhava
  • 761,203
  • 64
  • 569
  • 643