我想循环遍历目录中的所有文件并检查它们的权限(如果用户需要),但由于某种原因,我得到了这个错误:
./perms.sh: line 12: syntax error near unexpected token `;;'
./perms.sh: line 12: ` r) if [ -r $i ] then echo 'True' else echo 'False' fi ;;'
下面是我的代码:
#!/bin/bash
for i in *
do
echo "Do you want to check rights for $i (y/n)"
read marzi
if [ $marzi = 'y' ]
then
echo 'which commands to check? '
read check
case $check in
r) if [ -r $i ] then echo 'True' else echo 'False' fi ;;
w) if [ -w $i ] then echo 'True' else echo 'False' fi ;;
x) if [ -x $i ] then echo 'True' else echo 'False' fi ;;
*) echo 'unrecognized!' ;;
esac
else
echo "skipped $i"
fi
done
这和撇号有关系吗?
也许正确的内联if格式应该是
if [ -r $i ]; then echo 'True'; else echo 'False'; fi
确保对r, w和x进行更改