Erreur de syntaxe près du symbole inattendu « fi »

Fermé
BashLinux - 9 nov. 2015 à 15:37
jisisv Messages postés 3645 Date d'inscription dimanche 18 mars 2001 Statut Modérateur Dernière intervention 15 janvier 2017 - 10 nov. 2015 à 23:57
Bonjour,

J'ai l'erreur suivante sur mon bash :

Pouvez vous m'aider ?

Le bash :

#!/bin/sh

#Variable carte Ethernet
DEV=vmbr0

#Pour chaque IP dans le fichier list_ip.txt
#Verification si presence dans le fichier Iptable
# - si present, ne rien faire
# - si absent ajout via iptables -I

while read ip;
do
exist=$(iptables -L | grep $ip);

if [ -z = "$exist" ];

then
#Ajout dans Iptable
iptables -I FORWARD 1 -o $DEV -s $ip -m limit --limit 2000/sec -j ACCEPT
iptables -I FORWARD 2 -o $DEV -s $ip -j DROP
else
#Deja present pas d ajout dans Iptable
fi

done < list_ip.txt

3 réponses

jisisv Messages postés 3645 Date d'inscription dimanche 18 mars 2001 Statut Modérateur Dernière intervention 15 janvier 2017 934
Modifié par jisisv le 9/11/2015 à 18:10
Remarque ton nom de variable exists n'est pas très heureux (ressemble au mot-clé exit. Utilide plutôt des noms en UPPERCASE_WITH_UNDERSCORES

Ceci dit,
Pour ton test, ton utilisation est erronée , examine ceci:
johand@bata:~$ unset truc
johand@bata:~$ if [ -z $truc ] ; then echo BAD; fi
BAD
johand@bata:~$ if [ -z = "$truc" ] ; then echo BAD; fi
johand@bata:~$ truc=123
johand@bata:~$ if [ -z $truc ] ; then echo BAD; fi ; echo OK
OK

[ -z = $BLAH ] retourne toujours faux !

En outre, et c'est le plus important, le corps du else est vide ce qui fournit une erreur. Supprime cette branche ou mets-y une instruction valide.
exemple:
#!/bin/sh

if [ -z $1 ] ; then
   echo "No param"
else
# TTT
  echo "Param1 is $1"
fi

Gates gave ^W sold you the windows.
GNU gave us the whole house.(Alexandrin)
0