Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the at-sign @ mean in the bash command: date --date @...?

Tags:

bash

Searching the internet I found explanations only for '$@', meaning 'expand to positional parameters'. But I couldn't find anything about the @ sign by itself.

I stumbled over it in the third snipped of the accepted answer to this question: https://superuser.com/questions/611538/is-there-a-way-to-display-a-countdown-or-stopwatch-timer-in-a-terminal

Specifically:

date -u --date @$((`date +%s` - $date1)) +%H:%M:%S
like image 242
user1785730 Avatar asked Feb 25 '15 12:02

user1785730


People also ask

What is the date command in bash?

Date command is an external bash program that allows to set or display system date and time. It also provides several formatting options. Date command is installed in all Linux distros by default. Type date command in terminal which will display current date and time.

What does $# mean in bash script?

$# is the number of positional parameters passed to the script, shell, or shell function. This is because, while a shell function is running, the positional parameters are temporarily replaced with the arguments to the function. This lets functions accept and use their own positional parameters.

What does $() mean in bash?

Again, $() is a command substitution which means that it “reassigns the output of a command or even multiple commands; it literally plugs the command output into another context” (Source).

What does $@ mean in bash?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.


1 Answers

In the context you show, the @ is in the beginning of the --date argument to the date command:

date -u --date @$((`date +%s` - $date1)) +%H:%M:%S

In that case it means that the argument should be treated as the number of seconds since epoch, see an example in man date:

Convert seconds since the epoch (1970-01-01 UTC) to a date

$ date --date='@2147483647'

or:

$ date -u -d @0
Thu Jan  1 00:00:00 UTC 1970

This meaning of @ is defined by the date utility alone and not by bash.

like image 118
Lev Levitsky Avatar answered Oct 03 '22 22:10

Lev Levitsky