Really safe solution:
parent_dir="$(dirname -- "$(realpath -- "$file_name")")"
If your system does not have realpath
but does have readlink
, this should work:
parent_dir="$(dirname -- "$(readlink -f -- "$file_name")")"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…