击:用字符串操作(百分号) [英] Bash: manipulating with strings (percent sign)
本文介绍了击:用字符串操作(百分号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是一个百分号在bash处理字符串的时候是什么意思?例如,什么是 $ {0%/ *}
是什么意思?
What does a percent sign mean in bash when manipulating strings? For example, what does ${0%/*}
mean?
推荐答案
如果您使用@ fedorqui的资源,你会看到它是将剥离的最短匹配/ *
从第一个位置参数的结束。举个例子:
If you use @fedorqui's resource, you'll see it is going to strip the shortest match of /*
from the end of the first positional argument. An example:
example_foo(){
echo ${1%/*}
}
example_foo path/to/directory/sub_directory
# => path/to/directory
在例子中,我使用的第二个位置参数,因为第一个是函数的名称。
In the example I used the second positional argument since the first is the name of the function.
这篇关于击:用字符串操作(百分号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文