Utilisation de grep dans un script bash

Résolu
Bonjour,

J'ai un petit problème. Je voudrais utiliser la commande grep dans un scrip bash mais je n'y arrive pas. Voilà mon script:

#!/usr/local/bin/bash

source commun

recupererTexte_Toto()
{
    local path=$1
    local resultat="'grep Toto $path | cut -f 4 -d " "'"
    echo $resultat
}

LOG_DIR='~/mon_path/'

if [ "$#" -gt "1" ]
then
    echo "Usage:"
    echo "monScript ou monScript nomFichierDeLog"
    pkill -P $$
    exit 0
fi

if [ "$#" -eq "0" ]
then
    nomFichierDeLog=$LOG_DIR
    nomFichierDeLog=$nomFichierDeLog'nomExecutable.log'
else
    nomFichierDeLog=$LOG_DIR`$1`
fi

nomDeFichier=monFichier'__test__'

if [ "ls" -eq "0" ]
then
    rm $nomDeFichier
fi

recupererTexte_Toto $nomFichierDeLog > $nomDeFichier


Le problème c'est que la variable locale "resultat"ne contient pas le résultat du grep mais le texte de la commande faisant le grep??

Merci
--
Be water my friend, be water.
Configuration: Sun/Solaris 8

10 réponses

  1. Contributeur
    Salut,

    j'ai l'impression que tu as des quotes en trop :
    local resultat=`grep Toto $path | cut -f 4 -d " "`

    devrait faire l'affaire :)

    5