Howhit
Howhit

Reputation: 11

Problem getting the current time in seconds in bash shell

I need to retrieve the current time in seconds in a old machine (bash version 4.3) and this command is not working.

date +%s

It retrieves "%s" Any idea of what is wrong here?

Upvotes: 0

Views: 329

Answers (2)

Howhit
Howhit

Reputation: 11

nawk 'BEGIN {srand();time=srand();print time}' </dev/null

Upvotes: 1

Ivan
Ivan

Reputation: 7277

Try with printf function.

$ printf '%(%s)T' -1

1635846449

Upvotes: 0

Related Questions