Shell Script Basic Syntax

Source: Internet
Author: User

the meaning of several symbols
$#: On behalf of the following parameters "number", the above table as an example of this shows as "4";
[email protected]: for "$" "$" "$" "$" "$4" means, each variable is independent (enclosed in double quotation marks);
$*: Represents "$1c$2c$3c$4", where C is a separator character and is preset to a blank key, so this example represents "$ $ $4".
Shift
[email protected] scripts]# VI sh08.sh
#!/bin/bash
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '[email protected]'"
Shift # makes the first "shift of a variable"
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '[email protected]'"
Shift 3 # "shift of three variables" for the second time
echo "Total parameter number is ==> $#"
echo "Your whole parameter is ==> '[email protected]'"
Results
[email protected] scripts]# sh sh08.sh One, three four five six #给予六个参数
Total parameter number is ==> 6 #最原始的参数情况
Your whole parameter is ==> ' one, three four five six '
Total parameter number is ==> 5 #第一次偏移, look underneath and find the first one missing.
Your whole parameter is ==> ' both three four five six '
Total parameter number is ==> 2 #第二次偏移掉三个, and both three four are missing.
Your whole parameter is ==> ' five six '
If ... then
if [conditional judgment one]; then
When the conditional judgment is established, the instruction work content can be carried out;
elif [conditional judgment Type II]; Then
when the conditional judgment two is established, the instruction work content can be carried out;
Else
When the conditional judgment one and two are not established, the instruction work content can be carried out;
fi
&& representative and;
| | represent or;
So, in the judgment of using brackets, && and | | are different from the state of the directive.
["$yn" = = "Y"-o "$yn" = = "Y"] can be replaced by ["$yn" = = "Y"] | | ["$yn" = = "Y"]
Case ... Esac
Case $ variable name in
"First variable content")
Program Segment
 ;;
"Second variable content")
Program Segment
 ;;
  *)
other program execution segments that do not contain the contents of the first variable and the contents of the second variable
Exit 1
 ;;
Esac
function
function fname () {
Program Segment
}
Loops
While [condition]
Do
Program paragraph
Done
until [condition]
Do
Program paragraph
Done
For var in con1 con2 Con3 ...
Do
Program Segment
Done
For (initial value; limit value; execution step))
Do
Program Segment
Done

Shell script Basic syntax

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.