I am aware this is at high risk of being a duplicate, but in none of the other questions here I have found an answer to my problem. Below is a summary of what I have already tried.
I have an R script file file.r:
#!/usr/bin/env Rscript
print("Hello World!")
which is executable (chmod +x file.r), and which used to run nicely (last time I used it was about a month ago) by issuing:
$ ./file.r
However, today:
$ ./file.r
/usr/bin/env: 'Rscript\r': No such file or directory
In fact:
$ which Rscript
/usr/bin/Rscript
Thus I changed shebang to: #!/usr/bin Rscript, but:
$ ./file.r
/usr/bin: bad interpreter: Permission denied
Then I thought I would run it as super user, but:
$ sudo ./file.r
sudo: unable to execute ./file.r: Permission denied
Reading around I found that a fresh installation of R would solve my problem, so I un-installed and installed R. Unfortunately what I have written before still applies. Notice however that the following works with both shebang versions:
$ Rscript file.r
[1] "Hello World!"
What am I doing wrong?
#!/usr/bin Rscriptdefinitely doesn't make sense. I think you were trying to do something like#!/usr/bin/Rscriptto make a direct path to the executable. That would work if that's where Rscript is stored for you. It seems to me that the "\r" portion of the original error is what is causing the issue. Have you tried deleting the entire shebang line and retyping it?