You want:
epochTime=$(date +%s)
Or in sh
-compatible syntax:
epochTime=`date +%s`
The bash
man page describes this behaviour in detail.
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
Lösung
You want:
epochTime=$(date +%s)
Or in sh
-compatible syntax:
epochTime=`date +%s`
The bash
man page describes this behaviour in detail.