2024年6月20日(木) 5:47 Léa Gris <lea.g...@noiraude.net>: > Look like you did not find a proper answer there. Here is one simple > that involve no sub-shell at all and does exactly what your sub-shell > version does. > > declare -r SCRIPT_DIR=${BASH_SOURCE[0]%/*}
This doesn't work as explained by Will. BASH_SOURCE doesn't contain a slash when the script is specified as e.g. `bash a.sh' or `source a.sh'. > [...] it is not system agnostic anymore. POSIX 2024 containing realpath(1) was just published, though I'm not sure when/whether it will be available in very old systems. -- Koichi