How to simply combine field separated by a slash [duplicate]

How to simply combine field separated by a slash [duplicate]



This question already has an answer here:



How to simply combine field separated by a slash ?


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

echo $STRING
a/b/c



Please someone help? Thank you.



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




1 Answer
1



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:


IFS


str=$(IFS=/; echo "$list[*]")






I'm coming back slash at the end : a/b/c/

– Sat Net
Feb 9 '16 at 18:58






Check this working demo

– anubhava
Feb 9 '16 at 18:59






Interestingly, the problem is with me.:-( Thank you..

– Sat Net
Feb 9 '16 at 19:04

Popular posts from this blog

.name

Malaysia to Papua New Guinea by motorcycle?

List of Bhojpuri films