Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why am I getting unexpected-token error in this script?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading