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
Error:
[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]$
$'\r' is a representation of the carriage return character (CR) that is part of traditional DOS and Windows line endings (CR LF), but which is absent in traditional Unix-style line endings (LF).
The \r issue suggests you have edited the script file on a Windows machine. Windows uses \r\n as the line terminator while Linux (and most other operating systems) use \n alone. When you edit a file in Windows, Windows will add \r to the end of the lines and that will break your scripts.
When you're trying to run a command (with or without sudo ) and get an error message that reads "Command not found," this means the script or file you're trying to execute doesn't exist in the location specified by your PATH variable.
The shebang, #!/bin/bash when used in scripts is used to instruct the operating system to use bash as a command interpreter. Each of the systems has its own shells which the system will use to execute its own system scripts. This system shell can vary from OS to OS(most of the time it will be bash).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With