0

I've got two environment variables, one is:

 export COMMAND='sudo curl https://transfer.sh/n32gU/dockkub -o dockkub && kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address='

another is:

export EXIP='123.3.765.231'

How to connect it to one that looks like this:

sudo curl https://transfer.sh/n32gU/dockkub -o dockkub && kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=123.3.765.231

And store to EXEC variable

1 Answers1

2

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
Socowi
  • 25,550
  • 3
  • 32
  • 54