shebang line not working in R script

泄露秘密 提交于 2019-12-21 03:45:26

问题


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 examples I've seen)

$ ./shebang.r

I get permission denied.

Yes, Rscript is located in /usr/bin directory


回答1:


Make the file executable.

chmod 755 shebang.r



回答2:


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.



来源:https://stackoverflow.com/questions/3128122/shebang-line-not-working-in-r-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!