0
#!/bin/bash

source conf.ini

inotifywait -m -e create /$1path |
  while read file; do

if ($(echo $word | head -c 1)"=$1 then
    echo $file
cd $1inputpath
ls -l |grep $file*
zcat $file* > /tmp/$file
sort /tmp/$file > /tmp/$file.sorted
cd $1outputpath
 ls -l |grep $file
sort  $file > /tmp/$file.origsorted
diff /tmp/$file.origsorted  /tmp/$file.sorted
 if [ $? -eq 0 ];
 then
   echo OK
else
echo FAIL
echo $file
fi

fi
      done

I get below error:en do fthe file:

./FoldersegCompare: line 8: unexpected EOF while looking for matching `"'
./FoldersegCompare: line 32: syntax error: unexpected end of file

closed as off-topic by Mitch Aug 4 '15 at 6:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2

In don't know what you are trying to do with this script but looking at it first time i see the errors are because of this line :

if ($(echo $word | head -c 1)"=$1 then

Make it as :

if [ "$(echo $word | head -c 1)" = "$1" ]; then

while doing a check with if-then conditional construct use test ([) or [[ (bash-ism). Check help test for more info.

When you are doing if ($(echo $word | head -c 1)"=$1 then :

  • There are syntax errors, ( after if and " before =, perhaps you meant "$(echo $word | head -c 1)"

  • Also as you are using no test (or [[), the = simply suggests that you are doing a variable assignment. So you need [ (test) or [[ to make sure that you are comparing things

  • Also you have missed a ; before then which is a shorthand for newline (or you can put then at the next line)

Also your script seems inefficient (to be honest) to me by looking at the commands you have used to get the job (i don't know what) done. Perhaps you should go through the scripting answers posted here and other sites to get some idea about which tool to use in what situation, ask a new question to see what others suggest to solve your problem and of course use indentation.

1

Correct the following issues and check your script again here or see my corrections below

   1  #!/bin/bash
   2  
   3  source conf.ini
   4  
   5  inotifywait -m -e create /$1path |
   6    while read file; do
   7  
   8  if ($(echo $word | head -c 1)"=$1 then
          ^––SC1009 The mentioned parser error was in this simple command.
                                   ^––SC1073 Couldn't parse this double quoted string.
   9      echo $file
  10  cd $1inputpath
  11  ls -l |grep $file*
  12  zcat $file* > /tmp/$file
  13  sort /tmp/$file > /tmp/$file.sorted
  14  cd $1outputpath
  15   ls -l |grep $file
  16  sort  $file > /tmp/$file.origsorted
  17  diff /tmp/$file.origsorted  /tmp/$file.sorted
  18   if [ $? -eq 0 ];
  19   then
  20     echo OK
  21  else
  22  echo FAIL
  23  echo $file
  24  fi
  25  
  26  fi
  27        done
      ^––SC1072 Expected end of double quoted string. Fix any mentioned problems and try again.

E.G.

#!/bin/bash

source conf.ini

inotifywait -m -e create /"$1path" |
while read -r file; do
  if ("$(echo "$word" | head -c 1)"="$1"); then
    echo "$file"
    cd "$1inputpath" || exit
    find . -maxdepth 1 -type f -name "$file"
    zcat "$file"* > /tmp/"$file"
    sort /tmp/"$file" > /tmp/"$file".sorted
    cd "$1outputpath" || exit
    find . -maxdepth 1 -type f -name "$file"
    sort  "$file" > /tmp/"$file".origsorted
    diff /tmp/"$file".origsorted  /tmp/"$file".sorted
    if [ $? -eq 0 ];
    then
      echo OK
    else
      echo FAIL
      echo "$file"
    fi
  fi
done

And if you get something like this

./FoldersegCompare: line 5: inotifywait: command not found

simply install with

sudo apt-get install inotify-tools
  • That's too complex. Just tell him that there is a lonely " in line 8. ;-) – Pilot6 Jul 31 '15 at 19:17
  • @Pilot6 ok, done =) – A.B. Jul 31 '15 at 19:28
  • Yes that helped but i still get ./FoldersegCompare: line 25: syntax error near unexpected token fi' ./FoldersegCompare: line 25: fi' – Test priya Jul 31 '15 at 20:02
  • @Testpriya in my script? That's not possible. – A.B. Jul 31 '15 at 20:13
  • 1
    sudo apt-get install inotify-tools – A.B. Aug 3 '15 at 14:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.