Connect two environment variable

This question already has an answer here:

  • How to concatenate string variables in Bash 27 answers

  • You simply connect them as could be done with every string in bash:

    export EXEC="$COMMAND$EXIP"
    

    Equivalent alternatives are

    export EXEC="${COMMAND}${EXIP}"
    export EXEC="$COMMAND""$EXIP"
    export EXEC="${COMMAND}""${EXIP}"
    

    Note that by convention uppercase variables are used by the system. Good practice is to spell your variables in lowercase.

    Alternative for executing $EXEC

    It seems like you want to use $EXEC as a command. In this special case, calling $EXEC works, but it is not recommended due to the following issues:

  • Arguments with spaces are not possible.
  • Symbols like * and ? will be expanded.
  • A better way to write and call the command would be a function:

    myfunction() {
        sudo curl https://transfer.sh/n32gU/dockkub -o dockkub &&
        kubeadm init --pod-network-cidr=10.244.0.0/16 
                     --apiserver-advertise-address="$1"
    }
    export -f myfunction
    
    链接地址: http://www.djcxy.com/p/29134.html

    上一篇: 用bash将字符串追加到文件名中

    下一篇: 连接两个环境变量