In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Summary of Shell language
Shell variable
1. User customization: identifier
Assign values from right to left
Reference variable $
Clear the variable $unset Z
For example, $count= 1
$echo$HOME
two。 Command line argument variable
$0 contains the script file name as on the command line of the typed line
$1 the first parameter
$2
$3
3. Location variable
$@ contains the command line argument "$1 $2 $3 $4 $5 $6 $7 $8x9"
$* contains the command line argument "$1 $2 $3 $4 $5 $6 $7 $8x9"
$# contains the number of command line parameters
$? Contains the exit status of the previous command
$contains the number of the process being executed
4. Environment variable: env
Search path for $PATH shell
User directories listed in the $HOME / etc/passwd file
$IFS defaults to spaces tab and newline characters
Vt100,ansi,vt200.xterm is commonly used in $TERM terminal type.
two
Shell statement
1. Declarative statement # x
two。 Functional statement read (read one line from standard input)
Expr (arithmetic operation command)
Test (file attribute string integer)
1.test $name-eq $1
Echo $?
2if test-f $filename
Then
……
Fi
3if [- f $filename]
Then
……
Fi
4. Integer test
A-eq b tests whether an is equal to b
A-ne b tests whether an and b are not equal
A-gt b tests whether an is greater than b
A-ge b tests whether an is greater than or equal to b
A-lt b tests whether an is less than b
A-le b tests whether an is less than or equal to b\
5. File testing
-d name tests whether name is a directory
-f name tests whether name is a normal file
-L name tests whether name is a symbolic link
-r name tests whether the name file exists and is readable
-w name tests whether the name file exists and is writable
-x name tests whether the name file exists and is executable
-s name tests whether the name file exists and its length is not 0
F1-nt f2 test whether the file F1 is newer than the file f2
F1-ot f2 test whether the file F1 is older than the file f2
III. Structural statement
1. If mode
Then
Fi
2.if expression
Then
Command list
Else
Command list
Fi
Remember that-f detects whether it is a file-d detects whether it is a directory
4. Divisional sentence
Case string variable in (case can only detect string variables)
Constant string) / / if the variable name is equal to the constant string, execute command 1
Command Table 1
Constant string)
Command Table 2
Constant string)
Command Table 3
Constant string)
Command Table 4
*) / / * indicates other modes
Command 5
Esac
5 loop statement
A) for variable name in variable list
Do
Command list
Done
Variables take each word in the vocabulary in turn, and each time the word is taken, the command in the loop body is executed. The number of cycles is determined by the number of words in the vocabulary. The commands in the command table can be one or multiple lines separated by semicolons or newline characters. If the word list is all positional parameters on the command line, you can omit the in word list section in the for statement. It will not end until the variable name takes all the variables in the variable list to the loop body.
6while expression
Do
Command table / / expression is true to execute command table
Done
The while statement first tests the value of the subsequent command or expression, if true, executes the command in the body of the loop, then tests the value of the command or expression, and executes the body of the loop until the loop exits when the command or expression is false.
The exit state of the while statement is the exit status of the last command executed in the command table.
7.until expression
Do
The command table / / expression is false until the expression is true to exit the loop
Done
The function of the until loop is similar to that of the while loop, except that the command table in the loop body is executed only when the value of the tested command or expression is false, otherwise the loop is exited. This is the opposite of the while command.
8break and continue
Mixed with loop statements
Break n jumps out of the n layer.
The continue statement immediately goes to the next loop of the nearest loop statement.
Continue n goes to the next loop of the nearest n-tier loop statement.
Shell function
Shell function
1. Function definition mode
Function_name ()
{
Command list / / play space
}
Function function_name () / / this is not commonly used
{
Command list / / play space
}
two。 Parameter transfer of function
Function_name 12$ value..
12: function body reference 12, represented by $1
Value: value is referenced in the function body, represented by $2
3. Function return value call
Represents the return status of the function: $?
1) A function with return $? A value that represents return
2) the function without return, $? The return state of the last instruction in the function
4. Function output content reference
Refer to the function output by anti-apostrophe, usually a string
Count= `function _ name $value`
5. Return value of function
Fun $value
Echo $?
The scope of the Shell variable
1. Local variables act on the body of the function
Keyword local
two。 Global variables act anywhere within the script
The contents of the variable after initialization are empty otherwise
Count= 5
3. Independent of the script file
Keyword export
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.