巴什 - 获得最后目录名/文件名的文件路径参数 [英] Bash - get last dirname/filename in a file path argument
问题描述
我试图写一个post-commit钩子为SVN,这是我们开发服务器上托管。我的目标是尝试自动签承诺项目的副本,在那里它在服务器上托管的目录。不过,我需要能够传递到脚本,以结帐到我们的项目托管在同一子目录的目录串只读最后一个目录。
I'm trying to write a post-commit hook for SVN, which is hosted on our development server. My goal is to try to automatically checkout a copy of the committed project to the directory where it is hosted on the server. However I need to be able to read only the last directory in the directory string passed to the script in order to checkout to the same sub-directory where our projects are hosted.
例如,如果我做一个SVN提交到项目的榜样,我的剧本获得在/ usr /本地/ SVN /回购/例如,作为第一个参数。我需要得到的只是榜样的字符串的结尾,然后用另一个字符串连接,所以我可以检出到/服务器/根/例子,并立即看到变更后居住。
For example if I make an SVN commit to the project "example", my script gets "/usr/local/svn/repos/example" as its first argument. I need to get just "example" off the end of the string and then concat it with another string so I can checkout to "/server/root/example" and see the changes live immediately.
推荐答案
基本名
确实删除路径的目录preFIX:
basename
does remove the directory prefix of a path:
$ basename /usr/local/svn/repos/example
example
$ echo "/server/root/$(basename /usr/local/svn/repos/example)"
/server/root/example
这篇关于巴什 - 获得最后目录名/文件名的文件路径参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!