Distance from the last write and a period of time, the period has been followed by private food learning, or did not develop a regular record of the habit, today to write the first script.
After a few days of accumulation, learning the next shell script writing, the current master is not too mature, everything is certainly right from the beginning, write a simple bar (difficult will not write O (╯-╰) o).
The way this script is executed is to enter the birthday to calculate the current date distance from the birthday and how many days, if the birthday has been completed to calculate the next year's birthday time.
#!/bin/bash#program:# calculate how long it takes to have  A BIRTHDAY&NBSP, #History MG First releasepath=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/sbin:~/binexport pathecho -e " Enter your birthday, format: 2016/04/07 "while [ " $bir " == " " ]do read -p "Please enter your Birthday:" birdonembir=$ (date -d "$bir" +%j) curdate=$ (date +%j) difdate=$ (10#$ mbir-10# $curdate)) #这里之所以变量之前加10 # is to convert it to 10 binary again to count #, no then the default of 8 will be an error. if [ "$difdate" == 0 ];then echo "Happy birthday" to you! " #今天过生日elif [ $difdate -lt 0 ];then echo "and have $ ((-$difdate +365)) days to live." else echo "and have $difdate &Nbsp;days to live. "
The main thing is to use the date command to add and subtract dates, through the Read command to enter the birthday, the only thing to note is the conversion into a number of days after the subtraction will appear "value too great for base" This error, the online data said to be converted into 10 into the system can be, The variable is added "10#" before the arithmetic error is eliminated.
Although the script is simple, some details may also have to be modified, but at the beginning of the receipt of a lot of goods, continue to work!
This article from "Product small stream, into Jianghai" blog, please be sure to keep this source http://goodjoe.blog.51cto.com/9173556/1761389
Shell Scripting Learning