Dynamic variable names in Bash

后端 未结 14 1993
清酒与你
清酒与你 2020-11-21 05:38

I am confused about a bash script.

I have the following code:

function grep_search() {
    magic_way_to_define_magic_variable_$1=`ls | tail -1`
    e         


        
14条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-21 06:24

    An extra method that doesn't rely on which shell/bash version you have is by using envsubst. For example:

    newvar=$(echo '$magic_variable_'"${dynamic_part}" | envsubst)
    

提交回复
热议问题