Reference to a bash variable whose name contains dot

后端 未结 5 1902
盖世英雄少女心
盖世英雄少女心 2020-12-06 05:36

I have a bash variable: agent1.ip with 192.168.100.137 as its value. When I refer to it in echo like this:

echo $agent         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 06:14

    Is your code nested, and using functions or scripts that use ksh?

    Dotted variable names are an advanced feature in ksh93. A simple case is

    $ a=1
    $ a.b=123
    $ echo ${a.b}
    123
    $ echo $a
    1
    

    If you first attempt to assign to a.b, you'll get

     -ksh: a.b=123: no parent
    

    IHTH

提交回复
热议问题