PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 19, 2022

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

 November 19, 2022     bash, scripting, shell, syntax, unexpected-token     No comments   

Issue

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?


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



Answered By - stuffy
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing