1.java or javaweb project start container (tomcat,jetty,netty) through shell scripts written by yourself
2, basic master Linux-java-shell script
A. using Variables
b, command-line arguments
C,if ... else statement
D,case ESAC statement
E,for Loop
F,Shell functions
G,Shell function Parameters
First, the Java project started by its own Shell script
When looking at the source of the Superdiamond , the discovery is based on the netty write service side, the boot is through the Linux Shell script to start the.
Starting the Netty container is actually a java main function, like the original httpclient Start a server listening on a port as well.
Embed the container (jetty,Tomcat) inside the project and then through the Linux Shell Scripts to run the project, which is a good way to simplify the deployment of the program depends on the environment.
Then decided to look at the Linux shell script.
Second, master the Linux-java-shell script
2.1 Using Variables
With a defined variable, just precede the variable name with a dollar sign ($), such as:
1 your_name= "Mozhiyan"
2 echo $your _name
3 Echo ${your_name}
The curly brackets outside the variable name are optional, plus the curly braces are used to help the interpreter identify the bounds of the variable, such as the following: for skill inAda coffe Action Java
Do
echo "I am good at ${skill}script"
Done
If you do not add curly braces to the skill variable and write the echo "I am good at $skillScript", the interpreter will $skillScript As a variable (whose value is null), the result of the code execution is not what we expected it to look like.
It is a good programming habit to add curly braces to all variables.
2.2 Command-line arguments
The arguments passed to the script when the script is run are called command-line arguments. Command-line arguments are represented by a $n , for example, $ = for the first argument, and $ for the second argument, and so on.
Take a look at the following script: #!/bin/bash
echo "File Name: $"
echo "First Parameter: $ $"
echo "First Parameter: $"
echo "Quoted Values: [Email protected]"
echo "Quoted Values: $*"
echo "Total number of Parameters: $#"
Operation Result:
$./test.sh Zara Ali
File Name:./test.sh
First Parameter:zara
Second Parameter:ali
Quoted Values:zara Ali
Quoted Values:zara Ali
Total number of Parameters:2
2.3 If ... else statement
If ... elsesyntax for the statement:if [expression]then Statement (s) to was executed if expression is Truefiifexpressionreturntrue, Thenthe statement at the back will be executed;false, no statements are executed.
The final must befito the end of closureif,fiis thatifspell backwards and you'll find it in the back.
Attention:expressionand square brackets([ ])there must be spaces between them, otherwise there will be syntax errors.
As an example:#!/bin/sh
a=10
B=20
if [$a = = $b]
Then
echo "A is equal to B"
Fi
if [$a! = $b]
Then
echo "A is not equal to B"
Fi
Run Result:a is not equal to B
2.4 Case ESAC statement
case ... esac SWITCH ... CASE  Statement, which is a multi-branch selection structure. CASE  statement matches a value or a pattern, If the match succeeds, the matching command is executed. case statement format is as follows:
Case Value in
Mode 1)
Command1
;;
Mode 2)
Command2
Command3
;;
*)
Command4
;;
Esac
Cases:
Echo ' Input a number between 1 to 2 '
Echo ' Your number is:\c '
Read Anum
Case $aNum in
1)
Echo ' you select 1 '
;;
2)
Echo ' You select 2 '
;;
*)
Echo ' Do not select a number between 1 to 2 '
;;
Esac
2.5 for Loop
for Loop General format: for variable in list
Do
Command1
Command2 ... CommandN
Done
Cases:
For loop in 1 2 3 4 5
Do
echo "The value is: $loop"
Done
2.6 Shell function
function allows us to divide a complex function into several modules, which makes the program structure clearer and the code reuse more efficient. Like other programming languages, theShell supports functions as well. the Shell function must be defined before use.
the Shell functions are defined in the following format:
Function_name () {
List of commands
[Return value]
}
Cases:
#!/bin/bash
# Define your function here
Hello () {
echo "Url is http://see.xidian.edu.cn/cpp/shell/"
}
# Invoke your function call functions only need to give the function name, do not need parentheses.
Hello
2.7 Shell function Parameters
In the Shell , arguments can be passed to a function when it is called. Inside the function body, the value of the parameter is obtained in the form of a $n , for example, $ $ for the first argument, and $ = for the second argument ...
Examples of functions with parameters:
#!/bin/bash
Funwithparam () {
echo "The value of the first parameter is $!"
echo "The value of the second parameter is $!"
echo "The value of the tenth parameter is $!"
echo "The value of the tenth parameter is ${10}!" Note that the $ $ Cannot get the tenth parameter, and the tenth parameter requires ${10}.
echo "The value of the eleventh parameter is ${11}!" # when n>=10 , you need to use ${n} to get the parameters.
echo "The amount of the parameters is $#!" # Number of parameters
echo "The string of the parameters is $*!" # All arguments passed to the function
}
Funwithparam 1 2 3 4 5 6 7 8 9 34 73
Linux Script learning excerpt from: http://c.biancheng.net/cpp/view/6994.html
Application of the Linuxshell script in the Java boot container