3
I isolated a problem from a larger script that I am producing. I basically have a function that returns the current date and time in a specific format. I need every time the variable data_hora
is printed on the screen, its values are updated from the return of the execution of this function.
UPDATING
[28/12/2015]
Importantly, the variable should be interpolated into a string. In this case,
every time we print obter_data
the departure shall be the updated date.
This code is used in a script that is loaded only once (it composes my .dotfiles). Every time this variable is interpolated into a string it has returned to the date/time when the script source was loaded and not the current time.
To illustrate, we print the variable 3x with intervals of 1 second.
The desired output is as follows below:
[27/12/2015 22:26:00]
[27/12/2015 22:26:01]
[27/12/2015 22:26:02]
However, the example code below produces the following output:
[27/12/2015 22:26:00]
[27/12/2015 22:26:00]
[27/12/2015 22:26:00]
Below the source code:
function data_hora_atual {
echo `date +"[%d/%m/%Y %H:%M:%S]"`
}
obter_data=$(data_hora_atual)
data_hora=$(echo "${obter_data}")
echo ${data_hora}
sleep 1
echo ${data_hora}
sleep 1
echo ${data_hora}
Dener, I need the variable to be interpolated inside a string. I didn’t leave it specified in the question, I will update it.
– Arthur Alvim