I'm looking for bash one liner that adds a new line after each list item. If I call the script like:
./script arg1 arg2 arg3
I want the output to be
arg1 arg2 arg3
I tried different options for the following. A new line is not added. Any regular char is added.
# pretty much works except for an extra space list=${@/%/x} echo "$list" # appends 'n' list=${@/%/\n} echo "$list" # appends nothing list=${@/%/$'\n'} echo "$list" # appends nothing, \x078 would append 'x' list=${@/%/$'\x0D'} echo "$list" # appends nothing CR=$'\n' list=${@/%/$CR} echo "$list" # same issues with arrays tmp=( $@ ) list=${tmp/%/\n} echo "$list"
What fix or alternative do you suggest? I obviously could write a loop or call tr, but exactly what I thought I managed to avoid when replacing bash.
source share