-1

how can I assign the output of the below command to a variable in a while loop?

echo $(( `date +%s` - `stat -L --format %Y $"/root/path/$output_file"` ))

This command checks the age of the file in a path, echo works successfully, but when I want to assign it to a variable, it give "command not found" error or may be I do not know how to assign the value of it to a variable properly.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • `$"..."` is syntax for looking up strings in translation tables. Surely your filenames aren't mapped through a `.po` file to their native-language equivalents. – Charles Duffy Sep 27 '18 at 21:24
  • Anyhow, it would be very helpful here if you showed the syntax whereby you attempted to do the assignment. Right now you're showing us your *working* code, whereas we'd need to see your *broken* code (and the specific error it generates) to know what's wrong. (Spaces around the `=` are one of the most common mistakes that will cause a "command not found" from an assignment, btw). – Charles Duffy Sep 27 '18 at 21:25

1 Answers1

0
age=$(( `date +%s` - `stat -L --format %Y $"/root/path/$output_file"` ))

Best to use $(...) rather than backticks. And the $ isn't needed before the file name.

age=$(( $(date +%s) - $(stat -L --format %Y "/root/path/$output_file") ))
John Kugelman
  • 349,597
  • 67
  • 533
  • 578