I'm new to shell scripting and i'm trying to dynamically form the query based on several conditions. here is the code snippet
if [[ $(id -u) -eq 0 ]]
then
SSH_COMMAND="${cmd} > ${LOG_OUTPUT_FULL_PATH}/kubectlnodes.log"
else
SSH_COMMAND="'echo paass | sudo -S sh -c '${cmd} > ${LOG_OUTPUT_FULL_PATH}/kubectlnodes.log''"
fi
#echo "executing ${SSH_COMMAND}"
$(${SSH_COMMAND})
my command is written to SSH_COMMAND variable correctly but when executing the command, it execute the echo first and my entire command is failing. I tried the following format to execute the full command in SSH_COMMAND variable ${SSH_COMMAND} and $(${SSH_COMMAND}) but both are partially execute and failing the command.
Appreciate any inputs to this