Test file exists in bash script

    0

    0

    bashfileexists•••

    The code above will check to see if the file "/dossier/fichier.txt" exists, and if it does, it will print "Mon fichier existe"….If the file doesn't exist, then the code will print "Mon fichier n'existe pas".

    Library: Scripting et automatismes

    #!/bin/bash
    MON_FICHIER="/dossier/fichier.txt"
    if [ -e $MON_FICHIER ]
    then
      echo "Mon fichier existe"
    else
      echo "Mon fichier n'existe pas"
    fi
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.