linux脚本打印变量,bash – 使用shell命令的输出作为变量

本文深入探讨了Bash shell中的参数扩展机制,特别是重点讲解了带有感叹号的间接扩展。这种扩展允许使用变量的值作为另一个变量的名字来获取其值,对于复杂脚本编程非常有用。文中详细阐述了何时使用括号、如何处理多位数字参数以及间接扩展的特殊情况,帮助读者理解这一高级Bash特性。
摘要由CSDN通过智能技术生成

${parameter}

The value of parameter is substituted. The braces are required when parameter is a positional parameter with more than one digit,or when parameter is followed by a character which is not to be interpreted as part of its name.

If the first character of parameter is an exclamation point (!),a level of variable indirection is introduced. Bash uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution,rather than the value of parameter itself. This is known as indirect expansion. The exceptions to this are the expansions of ${!prefix*} and ${!name[@]} described below. The exclamation point must immediately follow the left brace in order to introduce indirection.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值