What is indirect expansion? What does ${!var*} mean?

前端 未结 5 1566
野趣味
野趣味 2020-11-22 05:28

I\'m reading \"Bash Guide for Beginners\". It says:

If the first character of PARAMETER is an exclamation point, Bash uses the

5条回答
  •  迷失自我
    2020-11-22 06:02

    There appears to be an exception when the given "indirection" ends in a *, as it does here. In this case, it gives all variable names that start with the part you specified (N here). Bash can do that because it tracks variables and knows which ones exist.

    True indirection is this:
    Say I have a variable $VARIABLE set to 42, and I have another variable $NAME set to VARIABLE. ${!NAME} will give me 42. You use the value of one variable to tell you the name of another:

    $ NAME="VARIABLE"
    $ VARIABLE=42
    $ echo ${!NAME}
    42
    

提交回复
热议问题