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

1 Answer 1

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))
Sign up to request clarification or add additional context in comments.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.