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

📄 ind-ref.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash# ind-ref.sh: Indirect variable referencing.# Accessing the contents of the contents of a variable.a=letter_of_alphabet   # Variable "a" holds the name of another variable.letter_of_alphabet=zecho# Direct reference.echo "a = $a"          # a = letter_of_alphabet# Indirect reference.eval a=\$$aecho "Now a = $a"      # Now a = zecho# Now, let's try changing the second-order reference.t=table_cell_3table_cell_3=24echo "\"table_cell_3\" = $table_cell_3"            # "table_cell_3" = 24echo -n "dereferenced \"t\" = "; eval echo \$$t    # dereferenced "t" = 24# In this simple case, the following also works (why?).#         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" takes the two arguments "echo" and "\$$t" (set equal to $table_cell_3)echo# (Thanks, Stephane Chazelas, for clearing up the above behavior.)# Another method is the ${!t} notation, discussed in "Bash, version 2" section.# See also ex78.sh.exit 0

⌨️ 快捷键说明

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