将文件的最后一部分路径存储在变量中?

Moh*_*deh 0 windows unix bash command-line-interface

将文件的最后一部分路径存储在变量中?

我有路径,例如:- $1=/path1/path2/path3

我想存储path3在变量中

x=path3

我如何做到:- 1-windows 2-unix

Jul*_*ano 5

您可以使用参数扩展basename实用程序。

x=${1##*/}

x=$(basename "$1")
Run Code Online (Sandbox Code Playgroud)