Home > Blockchain >  How to avoid printing None by aws CLI when no data found?
How to avoid printing None by aws CLI when no data found?

Time:11-06

I'm searching for values in DynamoDB like this:

aws dynamodb get-item --table-name table --key '{"name": {"S":"test"}}' --output text --query Item.value

If the item was not found, it prints None. How to avoid that and print an empty string instead?

CodePudding user response:

You may want to have a default empty string value if nothing was found for the Item.value you are looking for:

aws dynamodb get-item --table-name table --key '{"name": {"S":"test"}}' --output text --query 'Item.value || ``'

CodePudding user response:

You could re-direct to /dev/null?

aws dynamodb get-item --table-name table --key '{"name": {"S":"test"}}' --output text --query Item.value > /dev/null 2>&1

Be careful, because by doing so, you redirect both stdout and stderr to /dev/null. So if there is some error, you won't see it.

  • Related