'\r': 未找到命令 [英] '\r': command not found

查看:117
本文介绍了'\r': 未找到命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

echo "Select your option:"
echo "1. Change ip address"
echo "2. Add route"
echo "3. Reboot"
echo "4. Exit"
read A
case $A in
    1)
            echo "Add Ip address"
            read IP
            echo "Add Netmask"
            read Netid
            echo "Add name of interface"
            read Interface
            ifconfig ${Interface} ${IP}/${Netid}
            if [ $? -ne 0 ];then
                    echo "Ip address not configured"
            fi
            ;;
    2)
            echo "Add Destination"
            read dst
            echo "Add Netmask"
            read Netid
            echo "Add Gateway"
            read gw
            route add $dst mask $Netid gw $gw
            if [ $? -ne 0 ];then
                    echo "Route not added"
            fi
            ;;
    3)
            reboot
            ;;
    4)
            echo "Bye"
            exit 0
            ;;
    default)
            echo "Wrong selection"
            exit 1
esac

错误:

[b104@b104 Downloads]$ ./NetworkUtility.sh 
./NetworkUtility.sh: line 1: $'\r': command not found
Select your option:
1. Change ip address
2. Add route
3. Reboot
4. Exit
1
': not a valid identifier 7: read: `A
./NetworkUtility.sh: line 8: $'\r': command not found
./NetworkUtility.sh: line 9: syntax error near unexpected token `newline'
'/NetworkUtility.sh: line 9: `case $A in 
[b104@b104 Downloads]$ 

推荐答案

您似乎有 Windows 样式的行尾 (\r\n) - 您需要将它们更改为 unix 样式 (<代码>\n).如果您安装了 dos2unix,则可以使用它.您也可以使用 sedawk 来实现.

It seems that you have Windows style line endings (\r\n) - you need to change them to unix style (\n). If you have dos2unix installed you could use it. You could also do it using sed or awk.

这篇关于'\r': 未找到命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆