I am trying to build a commandline based on a variable VAR1.
If its empty it needs to be set as --arg1 1, else --arg2 $VAR1
This is a simple a script
#!/bin/bash -x
export VAR1=1 # Setting this myself for now
if [[ -z $VAR1 ]]
then
VAR2="--arg1 1"
else
VAR2="--arg2 \"$VAR1\""
fi
my_command $VAR2
When I execute this single quotes are added across $VAR1
my_command --arg2 '"1"'
I need the output to be
my_command --arg2 "1"
If you have better approach please do post.