如何从字符串中截取最后一个“/script.sh”部分?

Lan*_*nes 2 shell

我怎么能修改这个输入:

/home/USER/Desktop/script.sh
Run Code Online (Sandbox Code Playgroud)

到这个输出:

/home/USER/Desktop/
Run Code Online (Sandbox Code Playgroud)

...使用bashperl?

当然script.sh可以是任何东西:(例如scrasdfipt.sh,等)以及它之前的路径可以是任何东西。

Phi*_*ath 9

dirname /home/USER/Desktop/script.sh