Shell Programming in CentOS

Source: Internet
Author: User
Tags chmod file permissions

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

Related Article

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.