Shell basic Syntax (i)

Source: Internet
Author: User

Composition + Execution
    • Need to add #! at the beginning /bin/bash

    • Lines that begin with # are interpreted as explanatory notes

    • The name of the script ends with. SH and is used to differentiate between this is a shell script

    • There are two methods of executing

      chmod +x 1.sh;./1.sh

      Bash 1.sh

    • View the script execution process

      Bash-x 1.sh

    • To see if the script is syntactically incorrect

      Bash-n 1.sh


Date command syntax
# date      //Simple Display current date 2017  09 month  12 Day   Tuesday  21:26:09  cst[[email protected] ~]# date +%y   //  simple four-digit    "year" 2017[[ email protected] ~]# date +%y   //  two digits      "year" 17[[ email protected] ~]# date +%m   // minute  "Minutes" 32[[email  protected] ~]# date +%m   // month     "Month" 09[[email  protected] ~]# date +%S   // Second    "Seconds" 21[[email  protected] ~]# date +%H   // Hour      "Hours" 21 [[email protected] ~]# date +%d   // date       "Date" 12[[email protected] ~]# date +%d   //   installation how to output in English format      "Month Day" 09/12/17[[email protected] ~]# date +%y%m%d       //  four-digit     "Month Day" 20170912[[email protected] ~]# date +%y%m%d        //  Two digits     month Day 170912[[email protected] ~]# date +%f            //  Special format   "Month Day" 2017-09-12[[email  protected] ~]# date +%T              Special formats   "hours and Seconds" 21:40:22[[email protected] ~]# date +%h%m%s        //  Combo     "hours/minute" 214500[[email protected] ~]# date +%h: %m:%s     //  custom     "hours/Minutes" 21:45:07[[email protected] ~]#  date +%w           // week      "Weeks" 2[[email protected] ~]# date +%w            //  weeks    37[[email protected] ~]# date -d  " -1  Day " +%F       //  Yesterday 2017-09-11[[email protected] ~]#  date -d  " -1 month"  +%F     //  last month 2017-08-12[[email  protected] ~]# date -d  " -1 years"  +%f     //   Last year 2016-09-12[[email protected] ~]# date -d  " -1 hour"  +%T       //  the past hour 21:00:33[[email protected] ~]# date +%s            //  How many seconds has it been since 1970?     timestamp      1505225506 conversion Timestamp at a point in time: (August 8, 2018 8:8 8 seconds Away 1970 years elapsed how many seconds) [[email protected] ~]#  date +%s -d  "2018-08-08 08:08:08 "1533686888 based on timestamp   get a specific time [[email protected] ~]# date -d @ 15,336,868,882,018 years  08 month  08   Wednesday  08:08:08 CST


Variables in the shell
    • When using conditional statements, the variable if [$a-gt 1] is often used; Then ...; Fi

    • Replace N=wc-l 1.txt with a variable when referencing the result of a command

    • When writing and user interaction scripts, variables are also essential for read-p "Input a number:" N; Echo $n If you don't write this n, you can use $reply directly.

    • Built-in variables $, $ $, $ ... $ $ represents the script itself, the first parameter, the $ A second ... $ #表示参数个数

    • Mathematical Operation a=1;b=2; c=$ (($a + $b)) or $[$a + $b]


Shell basic Syntax (i)

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.