Bash Script - \R: Command Not Found

Bash Script - \R: Command Not Found

I wrote script in bash but I have problem when I try run it by terminal. I tried on Ubuntu and Debian.

For example, this is bash script:

#!/bin/bash
clear

when I run it by this commands:

bash name.sh

or

. name.sh

I got that error

bash: $'clear\r: command not found

in my script I have that for every line.

2

1 Answer

"\r" is how bash prints the Carriage Return character. ("^M,0x0B) that some other systems use as part of their End-of-Line marker ("^M^J", Carriage Return, followed by LineFeed). Linux uses only "^J" (LineFeed) at End-of-line.

One way of clearing out the "\r" characters is through dos2unix, in the package of the same name.

Another way is:

tr -d "\r" <name.sh >a.tmp
mv a.tmp name.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.