Frage

I have a simple bash file script that I need to get the epoch time and set a variable in the bash file as that epoch time so I can insert it as a string later in some code...

I know that :

date +%s

gives me the epoch time, but I tried the following and none seem to work...

epochTime=(date +%s)

epochTime=date +%s

epochTime="date +%s"

Many thanks in advance, I’m sure there is a way, I’m still a little new to bash files

War es hilfreich?

Lösung

You want:

epochTime=$(date +%s)

Or in sh-compatible syntax:

epochTime=`date +%s`

The bash man page describes this behaviour in detail.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top