In one of my bash-scripts where I use a file to write the current system time, I noticed that the correct time only gets written to the file every second time the script runs.I did a second script to test it, and it shows the same behavior.The script:#!/bin/bashNOW=$(date +%F_%H:%M:%S)wtimestamp=/home/pazau/logfiles/overviewer-timestamptimestamp=$(<$wtimestamp)echo $NOW > $wtimestampecho $timestampThe system is Ubuntu 14.04 x64, and a Raspberry Pi model B with raspbian. The behavior is the same on both systems.Anything i'm missing?
Simple Bash script; Only works sometimes?
shell script
The time stored is already correct, you just need to reorder the instructions to get what you expect:#!/bin/bashNOW=$(date +%F_%H:%M:%S)wtimestamp=/home/pazau/logfiles/overviewer-timestampecho $NOW > $wtimestamptimestamp=$(<$wtimestamp)echo $timestamp