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
  • 34,080
  • 14
  • 96
  • 122
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
  • 713,503
  • 59
  • 514
  • 593