690 shaares
3 liens privés
3 liens privés
1 résultat
taggé
basedir
Parce que la ligne $(dirname $0) ne marche pas avec les appels du type . ./<script> ou les liens ou les su - ...
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
et si le script est un lien :
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"