Shell Scripting Learning

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.