\r character in shell script

后端 未结 6 1949
执笔经年
执笔经年 2020-11-30 05:05

I get the below error while trying to execute a shell script,

$\'\\r\': command not found: line 2:

Please suggest a solution for the same.

6条回答
  •  天命终不由人
    2020-11-30 05:42

    I had the same error and what I did was to transform the characters '\r' to '\n'. using this line:

    tr '\r' '\n' < oldfile.sh > newfile.sh
    mv newfile.sh oldfile.sh
    chmod +x oldfile.sh
    ./oldfile.sh
    

    I think you could also delete the '\r' characters by using:

    tr -d '\r' < oldfile.sh > newfile.sh
    

    tr is the command trasnform, and the -d is delete the following character.

    I think the shell actually doesn't like '\r' character.

提交回复
热议问题