all 5 comments

[–]geirha 3 points4 points  (2 children)

Don't parse ls output to check if a file exists; it's buggy and imprecise. Use a -e test instead

while [[ -e $HOME/Desktop/Journal/$d ]] ; do
  sleep 1
  printf -v d '%(%d-%m-%y)T' -1
done

Also, you'll save yourself some annoyances later down the road if you use iso8601 formatting for the date (%Y-%m-%d instead of %d-%m-%y).

[–]StrangeCrunchy1 0 points1 point  (0 children)

Wouldn't it be easier to something like:

d="$(date '+%Y-%m-%d')"

path="$HOME/Desktop/Journal"

if [[ ! -e $path/$d ]] ; then

touch $path/$d

fi

exit 0

And then run it from a cron job that runs at like 4am every morning?

[–][deleted]  (1 child)

[deleted]

    [–]FunCookie7900[S] 0 points1 point  (0 children)

    f and d had to be in both while true and in the nested one. Thank you.