开发者

How to parse out the end of a path in a unix shell script?

I have a .sh unix shell script that receives as a parameter a path, say /home/test/user1. So, in the variable ${1}, that is the parameter开发者_JAVA百科.

I want to create a file whose name is based on the last part of that path, user1. How can I parse that path to retrieve the last piece of the path?


I think you are looking for the basename command.

$ basename /home/test/user1
user1

Edit: (in response to your comment)

In a shell-script variable, you need backticks:

END_OF_PATH=`basename "${1}"`
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜