0

I am doing a simple script. I have to update the stored date value. For example

ss=date; sleep 5; echo $ss;

It is showing old date. How to update the date after 5 seconds

peer mohammed
  • 19
  • 2
  • 8

1 Answers1

0

to update a variable it must be re assing: $(..) is a command substitution it is expanded to output of specified command.

ss=$(date)
...
ss=$(date)

SECONDS is a special variable which contains the number of seconds since bash process is running, to have a value changed every 5 seconds, following can be used.

echo $((SECONDS/5))
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36
  • duplicate from https://stackoverflow.com/questions/10402537/change-variables-in-bash – Brighter side Oct 18 '17 at 09:08
  • Thanks Nahuel. how to reassign the same variable. If i am having an variable a=`date`;if i am going call in a loop after some time. how to reassign the current date. is there any other way – peer mohammed Oct 18 '17 at 11:11