How to remove carriage return and newline from a variable in shell script

前端 未结 6 1808
挽巷
挽巷 2020-12-01 05:57

I am new to shell script. I am sourcing a file, which is created in Windows and has carriage returns, using the source command. After I source when I append som

6条回答
  •  感情败类
    2020-12-01 06:55

    You can use sed as follows:

    MY_NEW_VAR=$(echo $testVar | sed -e 's/\r//g')
    echo ${MY_NEW_VAR} got it
    

    By the way, try to do a dos2unix on your data file.

提交回复
热议问题