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

What does the '@' mean before a bash variable?

I’m working on a bash script that checks if a backup has been made in the last X days. The script must be run on linux and macos. My problem is, that when it checks if it’s running on a linux or macos system, I don’t understand what the ‘@’ means before the ‘bckpT’ variable on linux part.

case "$OS" in
   DARWIN)
       lastBackup=$($DATE -u -r $bckpT +%F)
       ;;

   LINUX)
       lastBackup=$($DATE -d @$bckpT +%F)
       ;;

   WIN)
       $ECHO "No script for WIN"
       ;;

   *)
       help
       ;;
esac

When there isn’t the ‘@’, the output is:

/usr/bin/date: invalid date ‘1647907200’

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 :

In date command the @ sign tells the command to treat the following as seconds since epoch

In your case, it consider the param $bckpT value as seconds since epoch

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