“变量=${2%?}$i"是什么意思?在 bash 脚本中是什么意思? [英] What does "variable=${2%?}$i" mean in bash scripting?

查看:89
本文介绍了“变量=${2%?}$i"是什么意思?在 bash 脚本中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释一下下面的 bash 代码片段?

Can anyone explain the following bash snippet?

for i in $(seq 1 1 10)
do
   VAR=${2%?}$i
   break;
done

推荐答案

它从 $2(第二个位置参数)中删除尾随字符并将该值与 $i 连接起来

It removes the trailing character from $2 (second positional parameter) and concatenates that value with $i

示例:

$ v1="myvalue1x"
$ v2="myvalue2"
$ combined="${v1%?}$v2"
$ echo $combined
myvalue1myvalue2

有关替换如何工作的更多信息,您可以查看 bash 手册的 Parameter Expansion 部分

For more info how the substitution works you can check the Parameter Expansion section of the bash manual

这篇关于“变量=${2%?}$i"是什么意思?在 bash 脚本中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆