Get the App
SLTechnology News&Howtos  ›  Servers  › 

The initial version of shell scripting

Shulou Source: shulou.com Published: 2022-06-02 06:09:55 10月04日 Update

1. Shell scripts are executed in a top-down, process-oriented order.

2. File name format: xxx.sh

3. First line of file content: #!/ bin/bash

4. Shell scripts are all about putting commands together.

5. define variables

Shell script variables are defined as: key=value, note: = can not have spaces on both sides

Static variable definition: a='www.ruozedata.com'

Dynamic variable definition: b=`date` #variable b is to get the current time, call b when the current time dynamically

The method that uses variables in shell scripts: ${variable}, if you use variable a, it should be ${a}.

6. if judged

Can judge: integer, decimal, string, folder exists, file exists, etc.

Format: if [space xx = yy space] Note: Use a single equal sign, with a space before, after and on both sides of the expression.

Examples:

if [ '$a' = 'www.ruozedata.com' ]; then

echo "D3"

fi

7. A few common ways to write for loop in shell

Category 1: Digital Cycle

Example 1:

#!/ bin/bash

for((i=1;i

Tags: Scripts variables characters files strings spaces parameters commands methods patterns loops dynamics time time format equal sign line content writing single Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB OPPO Reno Xiaomi macOS