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

前端 未结 6 1801
挽巷
挽巷 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:53

    for a pure shell solution without calling external program:

    NL=$'\n'    # define a variable to reference 'newline'
    
    testVar=${testVar%$NL}    # removes trailing 'NL' from string
    

提交回复
热议问题