Linux-Shell programming

One: echo usage

echo -n -e      -n do not wrap --e escape

\a issue a warning sound; \t insert tab; \n newline;

(1) Output hello world without line break

(2) Insert two tabs before the output and hello word

(3) Output two blank lines

(4) Write a fruit store script, the output is as follows:

Elevate file permissions:

execute script 

Another way to execute the script 

Two: read usage

read -p -t -s -p print output used with input

  1. Write a script for login account and password, the output is as follows:

Enter: vim login.sh

Three: Use expr, let, (( )) to demonstrate addition, subtraction, multiplication, division, and remainder

Let needs to be called out with a variable

Four:

Redirection usage < , > , >> <input redirection > output redirection, overwrite the previous content >> append, continue to add the previous content

Use, create a test.txt, enter the content

(1) Output the hello world coverage to test.txt

(2) Append hello world to test.txt

(3) Redirect the test.txt file to the wc command

(4) Write a shell script to complete the disk partition, and use redirection to append the input fdisk /dev/sdb <<EOF...EOF

if1 , if conditional statement usage

(1) Compare strings with if

(2) Use if to compare integer sizes

(3) Use if to determine whether the file exists

(4) if condition is empty is false, non-empty is true

Enter vim if.sh

 

(5) Write an elif.sh script, enter the value of a number and compare the size with 10 -le is less than -gt is greater than

Input: vim elif.sh

2 , case usage

  Write a case.sh script, when the input and output parameters are 1, output Monday; when the parameter is 2, output Tuesday; otherwise, output nothing

Input: vim case.sh

3 , for usage

  (1) Write a for.sh script and compare the usage of $* and $@

$* This variable represents all the parameters in the command line, $* is to treat all the parameters as a whole

$@ This variable also represents all the parameters in the command line, but $@ treats all parameters separately

$# This variable represents the number of all parameters in the entire command line

Input: vim for.sh

 (2) Write a for1.sh script, input n from the command line, and calculate the sum of 1+2+...+n

Input: vim for1.sh

 

5. Custom function usage

  Write a fashion.sh script, define the summation function getSum of two input parameters, and implement the function call

Enter: vim fashion.sh

 

Guess you like

Origin blog.csdn.net/dengfengling999/article/details/124083509