如何连接两个变量,只有当两个变量的值都被分配给两个变量时,才能连接?
1. Assign $SERVER to $NODELIST if only $SERVER variable is set
2. Assign $NODE to $NODELIST if only $NODE variable is set
3. Concatenate $SERVER and $NODE [comma separated ]to $NODELIST if both $SERVER and $NODE is set
#!/bin/bash
SERVER='sn01,sn02'
NODE='cn01,cn02'
if [[ -z $SERVER ]] || [[ -z $NODE ]] ; then
NODE_LIST=$SERVER,$NODE
echo "$NODE_LIST"
elif [[ -z $SERVER ]] || [[ -z $NODE ]] ; then
NODE_LIST=$SERVER
echo "$NODE_LIST"
elif [[ -z $NODE ]] || [[ -z $SERVER ]] ; then
NODE_LIST=$NODE
echo "NODE_LIST"
echo "none of the variables specified"
但无法按照要求分配 "NODE_LIST "变量。