dimanche 26 juillet 2020

Shell Script null check doesn't seem to work

I am new to shell scripting. My issue is the loop isn't breaking on the condition provided since the if else doesn't seem to work for the null check.

#!/bin/bash

count=100
file_name="table-${count}.json"


download_command=(SOME_COMMAND)


continue=true
while "$continue"; do
    echo "${download_command[@]}"
    "${download_command[@]}" > ${file_name}
    next_token=$(jq .NextToken ${file_name})
    count=$((count+100))
    file_name="table-${count}.json"
    echo $next_token
    download_command=(MODIFIED_COMMAND_TO_USE_NEXT_TOKEN)

    if [[ -z $next_token ]]
    then
        continue=false
        break
    else
        echo "I am here"
    fi
    echo $continue
done

So, even when my next_token is printing as null, I still see the if condition going in the else block and printing 'I am here'. And the loop continues. I need to break the while loop when next_token is null.

Aucun commentaire:

Enregistrer un commentaire