开发者

shebang line not working in R script

I have the following script

#!/usr/bin/Rscript

print ("shebang works")

in a file called shebang.r. When I run it from command line using Rscript it works

$ Rscript shebang.r

but when I run it from the command line alone

$ shebang.r

It doesn't work. shebang.r command not found.

If I type (based on other ex开发者_开发知识库amples I've seen)

$ ./shebang.r

I get permission denied.

Yes, Rscript is located in /usr/bin directory


Make the file executable.

chmod 755 shebang.r


In addition to Sjoerd's answer... Only the directories listed in the environment variable PATH are inspected for commands to run. You need to type ./shebang.r (as opposed to just shebang.r) if the current directory, known as ., is not in your PATH.

To inspect PATH, type

echo $PATH

To add . to PATH, type

export PATH="$PATH:."

You can add this line to your ~/.bashrc to make it happen automatically if you open a new shell.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜