Creating a string variable name from the value of another string

前端 未结 3 903
花落未央
花落未央 2020-11-28 12:11

In my bash script I have two variables CONFIG_OPTION and CONFIG_VALUE which contain string VENDOR_NAME and Default_Vendor

3条回答
  •  借酒劲吻你
    2020-11-28 12:31

    I know that nobody will mention it, so here I go. You can use printf!

    #!/bin/bash
    
    CONFIG_OPTION="VENDOR_NAME"
    CONFIG_VALUE="Default_Vendor"
    
    printf -v "$CONFIG_OPTION" "%s" "$CONFIG_VALUE"
    
    # Don't believe me?
    echo "$VENDOR_NAME"
    

提交回复
热议问题