在bash中,dir=${0%/*}是什么意思?

In bash, what does dir=${0%/*} means?

我在研究bash脚本时发现了这段代码:

dir=${0%/*}

我怀疑大括号内的代码是正则表达式,但我不明白它是什么意思。有什么想法吗?

它不是正则表达式,但它是 Bash Hackers Wiki 中的 pattern match. It sets dir to the name of the script, which is [=11=], but without the last slash and any non-slash after it, if there is a slash in [=11=]. If there is no slash in [=11=], dir gets a copy of [=11=] unchanged. See "Parameter Expansion"