使用 control-m 字符获取意外的文件结尾

Getting unexpect end of file with control-m characters

我有一个简单的脚本,它给了我一个意外的文件结尾。我觉得一切都很好

#!/bin/bash
me="$(basename "$(test -L "[=10=]" && readlink "[=10=]" || echo "[=10=]")")"
if [ $# -ge 5 ]; then
    echo "OK"
else
    echo "$me <arg1> <arg2> <arg3> <arg4> <arg5>"
fi

在评论中与 OP 检查后得知 OP 可能在您的文件中使用了控制 M 字符使用 tr -d '\r' < Input_file > temp_file && mv temp_file Input_file 将脚本的实际名称替换为 Input_file 并尝试此命令,您那应该不错吧