为了账号安全,请及时绑定邮箱和手机立即绑定

判断 /home 下的文件类型,判断不了,请高手指教

判断 /home 下的文件类型,判断不了,请高手指教

慕斯6215715 2017-07-09 15:44:42
脚本:#!/bin/bashfor file in $(ls  /home)do  if     [ -L "$file" ]  then      echo "$file is lianjie";elif [ -d "$file" ]  then      echo "$file is mulu";elif [ -f "$file" ]    then       echo "$file is putong";   elif [ -S "$file" ]     then        echo "$file is socket";else      echo "$file is qita";fi   done运行结果:abc is qita cde is qitajp is qitals -l 查看结果-rwxr-xr-x. 1 root root    0 6月  23 05:30 abclrwxrwxrwx. 1 root root    3 6月  23 05:30 cde -> abcdrwxr-xr-x. 2 root root 4096 6月  23 05:30 jp
查看完整描述

2 回答

?
慕斯6215715

TA贡献1条经验 获得超0个赞

但是我把上面脚本for 循环改成当前目录for  file  in $ (ls/sh),是可以正确执行。我听老师讲课if判断,相当于如果,then相当于那么,如果为真,那么会执行 then,所以帮分析下是不是别的原因

查看完整回答
反对 回复 2017-07-13
?
angie

TA贡献56条经验 获得超8个赞

对于 test 而言,如果为真返回值是 0, 0 放在 if 判断里面,那肯定不会执行 then 里面的语句咯

查看完整回答
反对 回复 2017-07-10
  • 2 回答
  • 0 关注
  • 1557 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信