通过外壳脚本拒绝对猫的权限 [英] Permission denied on cat via shell script

查看:41
本文介绍了通过外壳脚本拒绝对猫的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在〜/bin/rclone_sync_ACD.log中的日志文件上的shell脚本中运行cat时遇到问题.这是外壳程序脚本中的这一行:

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

在终端中,如果键入 cat $ LOGFILE |尾部-1 ,它给出正确的输出.

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?

谢谢,PJ

推荐答案

要将命令的输出分配给变量,请将命令包装在反引号或 $()中.

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

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

您的命令执行了环境变量分配 RESULT = cat ,然后执行了命令 $ LOGFILE |在该环境中的尾巴-1 .由于 $ LOGFILE 不是可执行文件,因此出现错误.

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.

这篇关于通过外壳脚本拒绝对猫的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆