免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3110 | 回复: 2
打印 上一主题 下一主题

[文本处理] Bash Shell_文件属性判断 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2019-04-22 09:52 |显示全部楼层 |倒序浏览
新手一个,参照<<Unix Shell by Example>>Example 8.19学习shell编程。
执行sh FILEtesting后没有任何显示,请大家帮忙看看,非常感谢!

#!/bin/sh
#Scriptname: FILEtesting
FILE=/etc/resolv.conf
if [ -d $FILE ]
then
    echo "$FILE is a directory"
elif [ -f $FILE ]
then
    if [ -r $FILE -a -w $FILE -a -x $FILE ]
    then
        echo "You have read, write, and execute permission on $FILE"
    fi
else
    echo "$FILE is neither a FILE or a directory"
fi

论坛徽章:
0
2 [报告]
发表于 2019-04-22 10:57 |显示全部楼层
感谢jzsjm1002的指点,之前理解有误,我以为如果不是目录,就会输出显示"该文件既不是文件,也不是目录"

代码重新修改了一下
#!/bin/sh
#Scriptname: FILEtesting
FILE=./testing
if [ -d $FILE ]
then
    echo "$FILE is a directory"
exit
fi
if [ -f $FILE ]
then
    if [ -r $FILE -a -w $FILE -a -x $FILE ]
    then
        echo "You have read, write, and execute permission on $FILE"
    else
        echo "Sorry, you don't have permissions!"
    fi
else
    echo "$FILE is neither a file or a directory"
fi

论坛徽章:
0
3 [报告]
发表于 2019-04-23 10:04 |显示全部楼层
我的最终目的是NetDevOps,目前已经学了CentOS系统管理部分,sed/awk语法部分,awk编程简单了解了一下,没有打算深入。现在开始学习bash shell,深入学习,大概持续一到两个月。下一个阶段开始系统学习Python,大概三到四个月。最后是Ansible。有什么建议?

PowerShell看起来似乎跟这个关联不大?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP