BASH printf array with field separator and newline on last entry -


How can I print an array with a field separator between each value and a new line in BASH.

The closest I can get with a single printf is printf '% s |' "$ {AR1 [@]}" where | Field separator. The problem with this is that there is no line break at the end \ NI try to enter any combination or any line breaks on every entry or none!

Is there a way to do it on one line or me printf '% s' | "$ {Arr1 [@]}"; Printf "\ n"

thanks,

gerrant

Yes, for this you need two commands. Print '% s' | "$ {Array {@}}"; Resonance is completely conventional.

Alternatively, if you are sequential | , you can temporarily modify IFS , select the separator as your first letter, and "$ {array [*]}" :

  Use IFS = "| $ IFS"; Printf '% s \ n' "$ {array [*]}"; IFS = "$ {IFS: 1}"    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -