Home > Mobile >  Error in UNIX bash script. Syntax error near unexpected token
Error in UNIX bash script. Syntax error near unexpected token

Time:06-06

I'm getting error's in line 16 while trying to execute this bash script. The error's are like this: line 16: syntax error near unexpected token then' line 16: then muj=ls -l $fajlli | awk '{print $7}''

#!/bin/bash

if [ -f modified ]
then rm modified
fi
touch modified

muajt=`date | awk '{print $2}'`
ditet=`date | awk '{print $3}'`

tegjithafajllet=`ls`

for fajlli in $tegjithafajllet
do
            if[ -f $fajlli ]
16.         then muj=`ls -l $fajlli | awk '{print $7}'`
            dit=`ls -l $fajlli | awk '{print $8}'`
                 if[ $muajt = $muj -a $ditet = $dit ]
                 then echo $fajlli >> modified
                 fi
            fi
done

CodePudding user response:

Bash has very strict rule about whitespaces. You need a whitespace after if like if [ -f $fajlli ]

CodePudding user response:

try this

#!/bin/bash

if [ -f modified ]
then rm modified
fi
touch modified

muajt=$(date | awk '{print $2}')
ditet=$(date | awk '{print $3}')

tegjithafajllet=$(ls)
for fajlli in $tegjithafajllet
do
        if [ -f "$fajlli" ]; then
                muj=$(ls -l "$fajlli" | awk '{print $7}')
                dit=$(ls -l "$fajlli" | awk '{print $8}')
        fi
        if [ "$muajt" = "$muj" ] && [ "$ditet" = "$dit" ]; then
                echo "$fajlli" >> modified
        fi
done
  • Related