Tester l'égalité de deux chaines en bash

Résolu
Arrakis -  
 freakazoid -
Bonjour,

Je me sens un peu bete de poster pour ca mais bon ca fait une heure que je suis dessus:

J'essaye juste de tester si une chaine vaut "total"... :s

J'ai essayé :

if $a == "total"
if "$a" == "total"
if [ $a == total ]
if $a = "total"
if [ $a = "total" ]
if [ "$a" == "total" ]
if [ "$a" = "total" ]

rien a faire, je n'arrive pas a trouver la bonne synthaxe, je vous met mon fichier entier au cas ou :

#!/bin/bash

while read line
do
a=`echo $line | awk -F" " '{print $2}'`
if "$a" == "total"; then
echo $line
fi
done < fichierLog

exit 0

Merci de votre aide
Configuration: Windows XP
Firefox 2.0.0.14

8 réponses

  1. jipicy Messages postés 40842 Date d'inscription   Statut Modérateur Dernière intervention   4 898
     
    Salut,

    Tout d'abord désolé pour ta syntaxe qui passe pas à cause de certaines fonctionnalités de mise en page du site et notamment l'emploi des doubles crochets qui renvoie un lien URL ;-((
    Donc dans ce cas là, penser à ajouter un espace pour une meilleure mise en page...

    La bonne syntaxe est : [ "$var" = "xxx" ]
    [tmpfs]$ cat plop
    1 totaux mauvais
    2 total bon
    3 totalité mauvais
    4 totale mauvais
    5 Total mauvais
    6 toTal mauvais
    7 total bon
    8 tototal mauvais
    
    [tmpfs]$ cat foo.sh
    #!/bin/bash
    
    while read line
    do
    a=$(echo $line | awk -F" " '{print $2}')
    if [ "$a" = "total" ]; then
    echo $line
    fi
    done < plop
    
    exit 0
    [tmpfs]$ ./foo.sh
    2 total bon
    7 total bon
    
    [tmpfs]$
    ;-))
    16