• # en vrac

    Posté par (site web personnel) . En réponse au message SCRIPT SHELL. Évalué à 2. Dernière modification le 03 janvier 2020 à 20:03.

    En vrac formation accelérée

    #!/bin/bash
    [[ -e $elem ]] && echo "$elem existe"
    # ou
    if [[ -e $elem ]]; then
     echo "$elem existe"
    fi 
    [[ -d $dossier ]] && echo "$dossier est un dossier"
    [[ -f $fichier ]] && echo "$fichier est un fichier"
    # negation
    [[ ! -e $elem ]] && echo "$elem n'existe pas"
    # ou
    [[ -e $elem ]] || echo "$elem n'existe pas"
    for elem in *; do
     echo "Je parcours $elem"
    done
    # Recursif
    ## trouver les dossiers
    find . -type d
    ## trouver les fichiers
    find . -type f
    ## trouver les fichiers nommés toto*
    find . -type f -name "toto*"
    # boucle for sur find (non recommandé espace est un séparateur)
    for elem in $(find . -type d); do
     echo $elem est un dossier
    done
    # boucle while à préférer
    while read elem; do
     echo $elem est un dossier
    done < <(find . -type d)

    Is it a Bird? Is it a Plane?? No, it's Super Poil !!!