Home > Software design >  Why am I getting unexpected-token error in this script?
Why am I getting unexpected-token error in this script?

Time:11-07

I want to loop through all the files in the directory and check their perms (if user wants) but for some reason I'm getting this error:

./perms.sh: line 12: syntax error near unexpected token `;;'
./perms.sh: line 12: `  r) if [ -r $i ] then echo 'True' else echo 'False' fi ;;'

here is my code:

#!/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

does this have something to do with apostrophe?

CodePudding user response:

maybe correct inline if format should be

if [ -r $i ]; then echo 'True'; else echo 'False'; fi

make sure to make change for r and w and x

  • Related