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.
Below are the intial lines used in the script,
#!/bin/sh
if [[ $# -lt 1 ]]; then
echo "ERROR Environment argument missing <dev,test,qa,prod>"
export RC=50
exit $RC
fi
10. 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.
The character '\r' is carriage return. It returns the cursor to the start of the line. It is often used in Internet protocols conjunction with newline ( '\n' ) to mark the end of a line (most standards specifies it as "\r\n" , but some allows the wrong way around).
R-shell maintains a set of variables which can be defined and modified through a set of UNIX-like commands, and later accessed from independent user programs. R-shell commands generally fall into three groups: general commands, object commands and manipulator commands.
$() Command Substitution According to the official GNU Bash Reference manual: “Command substitution allows the output of a command to replace the command itself.
Your problem is that the file has Windows line endings. This can be caused by editing a file in Windows and trying to run it on a non-Windows system.
You can fix this problem using dos2unix
to convert the line endings:
dos2unix ConstruedTermsXMLGenerator.sh
The corresponding utility to convert in the other direction is unix2dos
.
Some systems have fromdos
and todos
.
You can use sed -i 's/\r$//' scriptname.sh
Replace the scriptname with actual script name.
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