gpt4 book ai didi

bash - 这个 shell 脚本中的 ${1%..} 是什么意思?

转载 作者:行者123 更新时间:2023-12-04 15:33:21 24 4
gpt4 key购买 nike

我有这样的脚本,

latex $1
asy ${1%.tex}.asy

我知道如果 $1=test.tex,那么 ${1%.tex}.asy 将是 test-1.asy ,但是这里的 1%. 是什么意思?如果我想让 ${1%.tex}.asy 成为 test.asy,我该怎么办?

最佳答案

来自 Bash Reference Manual :

${parameter%word}

${parameter%%word}

The word is expanded to produce a pattern just as in filename expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the % case) or the longest matching pattern (the %% case) deleted. If parameter is @ or *, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.

所以如果 $1 扩展为 text.tex 那么 ${1%.tex} 扩展为 text .

关于bash - 这个 shell 脚本中的 ${1%..} 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23792476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com