• # Dans le même esprit

    Posté par (site web personnel) . En réponse au message Script bash. Évalué à 3. Dernière modification le 03 novembre 2018 à 20:30.

    Une version améliorée avec de quoi manger pour tout comprendre lorsqu'on débute ;-)

    #!/bin/bash
    read -p 'veuillez indiquez un chemin ' chemin
    [ -d "${chemin}" ] || { echo "path ${chemin} not exists" 1>&2; exit 1; }
    cd "${chemin}"
    [ -x "${SHELL}" ] || { echo "shell ${SHELL} not executable" 1>&2; exit 2; }
    grep -q "${SHELL}" /etc/shells || { echo "${SHELL} not a valid shell" 1>&2; exit 3; }
    exec ${SHELL}

    J'ai mis quelques barrières de protection ici ou là ainsi qu'une petite gestion d'erreur. À noter qu'on lance comme dans l'original un sous shell ce qui est un choix possible selon ce que l'on souhaite...