⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ind-ref.sh

📁 BASH Shell 编程 经典教程 《高级SHELL脚本编程》中文版
💻 SH
字号:
#!/bin/bash# ind-ref.sh: 间接变量引用.# 访问一个以另一个变量内容作为名字的变量的值.(译者注: 怎么译都不顺)a=letter_of_alphabet   # 变量"a"的值是另一个变量的名字. letter_of_alphabet=zecho# 直接引用.echo "a = $a"          # a = letter_of_alphabet# 间接引用.eval a=\$$aecho "Now a = $a"      # 现在 a = zecho# 现在, 让我们试试修改第二个引用的值.t=table_cell_3table_cell_3=24echo "\"table_cell_3\" = $table_cell_3"            # "table_cell_3" = 24echo -n "dereferenced \"t\" = "; eval echo \$$t    # 解引用 "t" = 24# 在这个简单的例子中, 下面的表达式也能正常工作么(为什么?).#         eval t=\$$t; echo "\"t\" = $t"echot=table_cell_3NEW_VAL=387table_cell_3=$NEW_VALecho "Changing value of \"table_cell_3\" to $NEW_VAL."echo "\"table_cell_3\" now $table_cell_3"echo -n "dereferenced \"t\" now "; eval echo \$$t# "eval" 带有两个参数 "echo" 和 "\$$t" (与$table_cell_3等价)echo# (感谢, Stephane Chazelas, 澄清了上边语句的行为.)# 另一个方法是使用${!t}符号, 见"Bash, 版本2"小节的讨论.# 也请参考 ex78.sh.exit 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -