Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I see if a timestamp is before now or empty?

I’m trying to see if a timestamp is expired. Which it would be, if it’s before now or empty.

exp=1662023095
NOW=$(date +%s)
if [[ -z $exp || (($exp < $NOW)) ]]; then
  echo "Update token..."
else
  echo "Token still valid!"
fi

The always echo "Update token…". Can someone tell me what I’m doing wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

found in the man bash:

When used with [[, the < and > operators sort lexicographically using the current locale.

Give this a try:

if [[ -z "${exp}" ]] || (( exp < NOW )) ; then
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading