what condition can I use for this process

Viewed 54
if [ "$Retrieve_api_key" -x "$Create_retrieve_api_key" ]
then 
  echo " $Retrieve_api_key "
else
  echo " $Create_retrieve_api_key "
fi

so the values of the variable Retrieve_api_key= let say "curl -u abc" Create_retrieve_api_key=let say "curl -u 123"

What I'm trying to do is basically if "$Retrieve_api_key" value get printed then skip the next "$Create_retrieve_api_key" but if $Retrieve_api_key value doesn't get printed then execute "$Create_retrieve_api_key"

How do I go about this please? This is a Bash script.

1 Answers

You can try something like this

api_key=$(curl -u abc)
if [ -z "$api_key" ]
then
     api_key=$(curl -u 123)
fi
echo $api_key

Firstly, try to retrieve api key, if it is empty, then create it. Finally use it.

Related