linux – 显示文件权限的bash脚本提供了错误的输出
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux – 显示文件权限的bash脚本提供了错误的输出,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1662字,纯文字阅读大概需要3分钟。
内容图文
我正在学习bash,并希望你们能用以下脚本帮我解决发生的事情
#!/bin/bash
#primer if
if [ -f $file1 ]; then
echo "file1 is a file"
else
echo "file1 is not a regular file"
fi
#segundo if
if [ -r $file1 ]; then
echo "file1 has read permission"
else
echo "file1 doesnot have read permission"
fi
#tercer if
if [ -w $file1 ]; then
echo "file1 has write permission"
else
echo "file1 doesnot have write permission"
fi
#cuarto if
if [ -x $file1 ]; then
echo "file1 has execute permission"
else
echo "file1 doesnot have execute permission"
fi
在我看来,如果我更改文件权限并不重要,因为输出始终是相同的
fmp@eva00:~/Books/2012/ubuntu_unleashed$./script.sh
file1 is a file
file1 has read permission
file1 has write permission
file1 has execute permission
fmp@eva00:~/Books/2012/ubuntu_unleashed$ll file1
-rw-r--r-- 1 fmp fmp 0 Aug 30 13:21 file1
fmp@eva00:~/Books/2012/ubuntu_unleashed$chmod 200 file1
fmp@eva00:~/Books/2012/ubuntu_unleashed$./script.sh
file1 is a file
file1 has read permission
file1 has write permission
file1 has execute permission
fmp@eva00:~/Books/2012/ubuntu_unleashed$ll file1
--w------- 1 fmp fmp 0 Aug 30 13:21 file1
fmp@eva00:~/Books/2012/ubuntu_unleashed$chmod 000 file1
fmp@eva00:~/Books/2012/ubuntu_unleashed$ll file1
---------- 1 fmp fmp 0 Aug 30 13:21 file1
fmp@eva00:~/Books/2012/ubuntu_unleashed$./script.sh
file1 is a file
file1 has read permission
file1 has write permission
file1 has execute permission
file1可以是空的,但仍然输出相同,进行相同的测试
任何人都可以向我解释有什么问题吗?
谢谢
BTW这里的脚本是比较3的修改版本,在ubuntu发布的2011年版本(书籍网站http://ubuntuunleashed.com/)第233页
解决方法:
file1变量未定义.
你应该在你的脚本开头添加file1 =“file1”
内容总结
以上是互联网集市为您收集整理的linux – 显示文件权限的bash脚本提供了错误的输出全部内容,希望文章能够帮你解决linux – 显示文件权限的bash脚本提供了错误的输出所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。