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
Lỗi:' r': command not found
[[email protected] 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
[[email protected] Downloads]$
Tệp tập lệnh của bạn có chứa kết thúc dòng DOS/Windows ('\ r \ n'), đây là điều làm bạn bối rối. Hãy thử lưu nó với kết thúc dòng unix ('\ n'). –
Bạn có thể thực hiện 'tr -d" \ r " cleaned.sh', sau đó kiểm tra xem'./Cleaned.sh' có hoạt động tốt hơn không. –
Điều đáng tiếc nhất về câu hỏi này là bao lâu - hoàn toàn không có lý do gì để có một kịch bản nhiều hơn 20 dòng khi một dòng hai (với một shebang và một dòng trống) sẽ tạo ra chính xác cùng một vấn đề. –