[英]Permission denied, though files are chmod 777
这是我的代码:
#!/bin/sh
sudo touch /home/test/hello.txt
sudo chmod 777 /home/test/hello.txt
sudo touch /home/test/hello1.txt
sudo chmod 777 /home/test/hello1.txt
"$(sudo du -hs /home/test/*)" >> /home/test/hello.txt
"$(sudo sort -n /home/test/hello.txt)" >> /home/test/hello1.txt
head -3 /home/test/hello1.txt
在第7行,它给出了错误:权限被拒绝。 我已经制作了两个文件chmod 777,所以我不知道它来自哪里。
谢谢你的任何建议!
从du
删除$()
并对行进行sort
使它们如下所示:
sudo du -hs /home/test/* >> /home/test/hello.txt
sudo sort -n /home/test/hello.txt >> /home/test/hello1.txt
$()
获取括号内的操作结果,并尝试将其作为命令执行。 如果此结果不是可以运行的结果,您将收到各种错误消息。
权限被拒绝即将到来,因为$()
任何结果恰好出现在你的机器上也恰好是你无法执行的东西。 在我的脚本测试中,我也得到Is a directory
和command not found
。 它实际上与hello.txt
或hello1.txt
的模式hello1.txt
。
我应该提一下,我不确定你正在寻找的结果,所以做出上述改变可能会或可能不会得到你想要的。 然而,现在的脚本运行,给你生du
导致hello.txt
,善良的,在排序结果hello1.txt
。 如果您尝试从最小磁盘使用量到最大磁盘使用列表,则可能需要稍微调试排序(提示:尝试从du
取消-h
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.