开发者

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

开发者 https://www.devze.com 2023-03-19 01:37 出处:网络
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 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

精彩评论

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