• # Chez moi ça marche...

    Posté par (site web personnel) . En réponse au message [RÉSOLU] Bash utiliser variable dans une commande du style result=$(commande | grep $variable). Évalué à 3.

    Ton code est semble-t-il tout à fait correct, et en l'essayant, je n'ai aucune erreur.

     #!/bin/bash
     mountPoint="/media/monPath"
     result=$(mount | grep "$mountPoint" | wc -l)
     if [ ${result} = "1" ];then
     echo "montage effectif"
     else
     echo "montage not work"
     fi

    Ce que personnellement, j'aurais fait (puisque Bash) :

     #!/bin/bash
     mountPoint="/media/monPath"
     mount | grep -q " ${mountPoint}" || { printf '%s' "Mount NOK"; exit 1; }
     printf '%s' "Mount OK"

    Ou bien sans utiliser mount :

     #!/bin/bash
     mountPoint="/media/monPath"
     grep -q " ${mountPoint}" /etc/mtab || { printf '%s' "Mount NOK"; exit 1; }
     printf '%s' "Mount OK"