Bash script array to csv

前端 未结 2 1965
无人及你
无人及你 2021-01-21 00:08

I want to do comma separated string from my array. In my script i collecting data to array outputArr and then i want to echo it to check it out, but no

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-21 01:01

    Your array contains elements with carriage returns:

    $ foo=($'\rterminally yours' $'\r2204')
    $ echo "${foo[0]}"
    terminally yours
    $ echo "${foo[1]}"
    2204
    $ echo "${foo[*]}"
    2204inally yours 
    

    For your code, you can add the following to remove the carriage return from the variable:

    singleLine=${singleLine//$'\r'/}
    

提交回复
热议问题