I was working on a simple daemon example and noticed that the following command prints same value of time on every iteration.
/bin/bash -c "while true; do echo `date`; sleep 1; done"
Output:
Wed Dec 25 08:00:47 UTC 2013
Wed Dec 25 08:00:47 UTC 2013
Wed Dec 25 08:00:47 UTC 2013
However, If I put the above code in a script and then run the script, it gives the expected output.
#!/bin/bash
while true; do
echo `date`
sleep 1
done
Output:
Wed Dec 25 08:02:58 UTC 2013
Wed Dec 25 08:02:59 UTC 2013
Wed Dec 25 08:03:00 UTC 2013
How is this possible? Is this the expected output?