1.shell is a batch program, similar to the Windows BAT file
2. When writing the shell, the first line should be #! /bin/bash begins Execute the file using the bash shell.
3. Use the # comment (preferably note the function of the shell script in case you forget later)
4. The file name should end with. sh
5. Run-time, execution mode sh 1.sh;chmod +x 1.sh;./1.sh | | /root/test/1.sh (absolute path)
6.$? The return value of the command stores the variable
$#//Number of parameters
$//number of parameters. Extracting parameters
$//The name of the current script command
[Email protected]//Remove all parameters
$shift//Parameter shift left
7.1) Create the first script file,
$>touch a.sh;//Create a script file, modify the file permissions after creating the script file, everyone can execute the file, chmod a+x a.sh
$>#!/bin/bash
echo Hello World
This app will print except Hello World
7.2) #! /bin/bash
num=$#
echo num >>1.txt//This script prints out the number of input parameters
7.3) #!/bin/bash
Echo helloworld!
echo Parameters is $#!
echo Script ' s name is $.
7.4)
#!/bin/bash
echo $.
Shift.
echo $.
Shift.
echo $.
Shift.
echo $.
Shift.
8.if[$#-LT 1]//This sentence means that if the number of arguments is less than 1
if[$#-GT 1]//This sentence means that if the number of arguments is greater than 1
if COMMANDS; Then COMMANDS; [Elif COMMANDS; then COMMANDS;] ... [Else COMMANDS;] Fi
For ((: EXP1; exp2; exp3), do COMMANDS;
8.1) #!/bin/bash
num= [email protected] Remove all parameters
for ((i = 1; I <= num; i = $i + 1));d O
for (y = 1; y <= x; x= $x +1)); Do
Echo-n $y;
Done
echo;
Done
8.2) 99 Multiplication table
#!/bin/bash
I=1
Line=$1
while ((i<= $line)); Do
J=1
while ((j< $i)); Do
Echo-ne ${j}x${i}=$ ((j*i)) ' \ t ';
j=$ ((j+1));
Done;
i=$ ((i+1))
echo;
Done
Shell Programming in CentOS