-1

I created a .json file and saved it at ~/myfolder/myfile.json. Then I wrote a bash script. In which I first try to change the access rights, but I get the following error.

bash: $'\r': command not found
chmod: cannot access '/root/myfolder/myfile.json'$'\r': No such file or directory

Here is the script:

  #!/bin/bash
  chmod 600 ~/myfolder/myfile.json

I then came across the following post chmod: cannot access ‘\r’: No such file or directory

So instead of moving the file from windows to the container. I created the file with nano directly in the target folder. But I still get the same error

Does anyone have an idea what's the problem?

Fill07
  • 9
  • 1
  • 3
  • 1
    the file is in CRLF format. Use `dos2unix` to convert it to LF – phuclv May 19 '22 at 07:51
  • I tried already, but still receive the same error :/ – Fill07 May 19 '22 at 07:54
  • the problem is 99% chance caused by your CRLF line endings. What does `cat -v script.sh` show ? Do you see any caracters like `^M` showing ? – Aserre May 19 '22 at 08:12
  • Alright, solved it. When pushing my project on Windows with git bash, the format of the script was changed. So converting the script itself, using dos2unix myscript.sh fixed it. To prevent this from happening again, I have now added the following .gitattributes file to my project: `*.sh text eol=lf` – Fill07 May 19 '22 at 08:53

0 Answers0