Permission denied on cat via shell script [duplicate]

点点圈 提交于 2021-02-05 08:18:06

问题


I have an issue with running cat in shell script on a log file which is in ~/bin/rclone_sync_ACD.log. This is the line in the shell script:

RESULT=cat $LOGFILE | tail -1

But when running the script I get:

./rclone_sync: line 63: /Users/pjburnhill/bin/rclone_sync_ACD.log: Permission denied

In terminal, if I type cat $LOGFILE | tail -1, it gives the right output.

What permissions would the script need to have to access and print out the correct line?

Thanks, PJ


回答1:


To assign the output of a command to a variable, wrap the command in backticks or $().

RESULT=$(cat $LOGFILE | tail -1)

Your command performed the environment variable assignment RESULT=cat, and then executed the command $LOGFILE | tail -1 in that environment. Since $LOGFILE is not an executable file, you got an error.



来源:https://stackoverflow.com/questions/39982783/permission-denied-on-cat-via-shell-script

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