4 ms·
bash-scripting: 23:20, I was waiting on a public event for new year to happen. There was no big countdown screen visible. I checked my android phone if there i
by faebi 9y ago
bash-scripting:
23:20, I was waiting on a public event for new year to happen. There was no big countdown screen visible. I checked my android phone if there is any clock with seconds, nope (iOS has something I think). I usually would download an app but I am on holidays and there was no Wifi. So I thought, 40 minutes to go, lets fire up termux with ruby and make a oneliner. I discovered that I didn't install ruby yet. Ok, I need to use bash. MAN is also not installed yet. Termux thankfully has a 'help' command. It offers for "while": "while COMMANDS; do COMMANDS;> { COMMANDS ; }". I tried for 30 minutes, but there was always a syntax error.
Another solution would be "watch -n1 echo $(date)", but then I would have an update only every second. Also this somehow didn't work because of some buffer issues. It always showed the same time.
23:56, I give up.
Now at home, I lookup the syntax for while and here it is: "done" was missing. Easy to find out, unless you never use bash for scripting. I tried tons of keywords and combinations, but just couldn't remember that it was "done".
- mbrock 9y agoYour "watch" command didn't work because the first thing that happens is that your shell expands the $(date) word into the current date, and then it runs "watch -n1 echo 'Mon Jan 1 ...'". You should have just done "watch -n1 date". BTW, the manual for bash is really good: https://www.gnu.org/software/bash/manual/bash.pdf https://www.gnu.org/software/bash/manual/bash.pdf