-1

I have a script that runs daily to add/commit/push to github. I'm trying to change the commit message to the size of the commit, which will always be only 1 file, in the format of <date>.html.

I can reference the date using date "+%Y%m%d".html, which returns a valid filename in the terminal. However, when I try to stat it using stat --printf="%s" date\ "+\%Y\%m\%d".html, it returns the error stat: cannot stat ‘date +\\%Y\\%m\\%d.html’: No such file or directory.

I understand that it is not executing my date as a command. How do I go about doing this?

isopach
  • 1,783
  • 7
  • 31
  • 43
  • Possible duplicate of [How do I set a variable to the output of a command in Bash?](https://stackoverflow.com/questions/4651437/how-do-i-set-a-variable-to-the-output-of-a-command-in-bash) – oguz ismail Jun 11 '19 at 05:46

1 Answers1

2

You are passing the date ... part as a literal argument, not a result of Bash command, so you must wrap it into the $() construction.

stat --printf="%s" $(date "+%Y%m%d.html")

This will work.

trolley813
  • 874
  • 9
  • 15