script Q : how do I force bash to perform the math?
Hi
I want to know how old a file is so I've reduced the problem to give me two timestamps but: echo `date +%s` - `stat -c %Z howoldisthisfile.txt` gives 1235114433 - 1235093198 instead of 21235 I've tried () around various parts but just end up with syntax errors. How do I persuade bash to give up the result without assigning to variables. Many thanks kevin |
The mathematical operation syntax for bash is $(( )). I also recommend $() for command nesting instead of using the ` backticks
Code:
echo "$(( $(date +%s) - $(stat -c %Z howoldisthisfile.txt) ))" |
Expr way:
Code:
expr `date +%s` - `stat -c %Z howoldisthisfile.txt` Code:
echo "`date +%s`-`stat -c %Z howoldisthisfile.txt`" | bc |
Code:
# quick |
Quote:
Kevin |
All times are GMT -5. The time now is 12:59 AM. |