Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Basic knowledge of shell

Shulou Source: shulou.com Published: 2022-06-01 06:35:23 10月03日 Update

Self-built calibration time yum install-y ntp uses ntpdate time.fudan.edu.cn to calibrate time

Some of the most common uses of date in scripts:

Date +% F xxxx-xx-xx

Date +% T xx:xx:xx

Date +% Y prints the year in four-digit format

Date +% y prints the year in two-digit format

Date +% m month

Date + d date

Date +% H hours

Date +% M minutes

Date +% S seconds

Date +% s timestamp

Date +% w week, if the result shows 0, it means Sunday

Sometimes a day's date is used in the script: date-d "- 2 days" +% F

Define the format of the variable as the variable name = the value of the variable. You need to add the'$'symbol when referencing the variable in the script, which is consistent with the custom variable described earlier in shell.

Mathematical calculations should be enclosed in [] and with a'$'on the outside.

-lt (less than),-gt (greater than),-le (less than or equal to),-ge (greater than or equal to),-eq (equal to),-ne (not equal).

Read-p "Please input a number:" x

Read-p "Please input another number:" y

Sum=$ [$xylene roomy]

Echo "The sum of the two numbers is: $sum"

The read command is used in such a place to interact with the user, taking the string entered by the user as the value of the variable. The script execution process is as follows:

There is a $0, but it represents the name of the script itself.

If judgment statement; then

Command

Fi

If judgment statement; then

Command

Else

Command

Fi

(a) appears in if1.sh

Tags: Script variable format statement time condition loop representative function year number file date permission user directory face normal consistent no Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology MySQL Apple vpn