jeudi 1 novembre 2018

Trying compare 2 String arrays and i got error in Bash

i got some work to do and in last lines of my code i am trying to compare two arrays and i got some error in my if statement. i looked in every place and i cant find soloution why its happend

the error i got:

./bigBrother.sh: line 28: syntax error near unexpected token `if[ "$oldArray[@i]" == "$newArray[@j]" ]'
./bigBrother.sh: line 28: `                     if[ "$oldArray[@i]" == "$newArray[@j]" ]'

the code:

  #!/bin/bash
cd $1
if  [ ! -e "oldText.txt" ]
        then
        echo Welcome to the Big Brother
        touch oldText.txt
        ls > oldText.txt
        else
                let index=0
                while read line
                do
                        oldArray[index]=$line
                        index=$(( index + 1 ))

        done <oldText.txt
        touch newText.txt
        ls > newText.txt
                let index=0
                while read line
                do
                        newArray[index]=$line
                        index=$(( index + 1 ))
                done <newText.txt
                for i in "${oldArray[@]}"
                do
                flag=0
                        for j in "${newArray[@]}"
                        if[ "$oldArray[@i]" == "$newArray[@j]" ]
                        then
                        echo  $j
                        fi
                        done
                done
                fi

Aucun commentaire:

Enregistrer un commentaire