Friday, 15 January 2010

bash - zenity --calendar how to convert result to 'find -mtime' -



bash - zenity --calendar how to convert result to 'find -mtime' -

i have utilize zenity --calendar read date user. after it, have utilize in programme find parameter of alternative -mtime. zenity homecoming date in format 20.09.2014 , have no thought how count how many days ago was, necessary in -mtime option. help me , tell me how it? i've started learning bash , part of 1 exercise. help! :-)

you can utilize date command convert dates seconds since epoch, calculate difference in seconds , convert days. looks follows:

pickeddate=$(zenity --calendar) pickedseconds=$(date --utc +%s --date "$pickeddate") nowseconds=$(date --utc +%s) diffdays=$(( ($nowseconds - $pickedseconds)/86400 ))

or in 1 line:

echo $(( ($(date --utc +%s) - $(date --utc +%s --date $(zenity --calendar)))/86400 ))

bash calendar find zenity

No comments:

Post a Comment