Linux beginners, linux beginners
Linux features
1. Free and Open-Source
2. multithreading is supported. Multi-User
3. Good Security
4. superior memory and file management
5. linux requires at least 4 m-> embedded development
Disadvantages:
Relatively difficult operations
Command:
Shutdown-h now shutdown immediately
Shutdown-r now restart the computer
RebootRestart the computer now
Logout
Use vi to develop hello. java in linux
1 vi Hello. java
2 input I [enter the insert mode]
3 public class Hello {
Public static void main (String [] args ){
System. out. println ("Hello ");
}
}
4. Enter esc to enter the command mode]
5 input: wq [Save and quit] q! [Exit and do not save]
Enter ls [Current Directory]
Ls-l [Details]
6 compile Hello. java
Javac Hello. java
7 run
Java Hello
How to Develop c/c ++ programs in linux
Vi hello. cpp
# Include <stdio. h>
Int main (){
Printf ("hello! ");
Return 0;
}
Gcc Hello. cpp
./A. out
Add User useradd xiaoming
Add passwd xiaoming
I/o redirection
Output> overwrite output. May the content be overwritten> append output
Input <
2>: redirect error output
&> Redirect all outputs
Weak shell programming language
Strong: variables must be declared or even initialized before they can be used.
Weak: variables are declared, directly used, or even non-differentiated.
'Strong references do not replace variables
"" Weak reference for variable replacement
Variable VALUE assignment: VAR_NAME = VALUE
Variable type:
Environment Variable
Local variable)
Location variable
Special Variables
Local variable:
NAME = Jerry (entire bash process)
Echo $ NAME echo display characters
Variable reference: $ {}{} can be omitted sometimes.
Local variables:
Local VARNAME = VALUE (current code segment)
Environment variable: the scope is the current shell process and its sub-processes.
Export VARNAME = VALUE "export"
Starting any script in the command line will start a shell Process
The script automatically executed by the system (not started by the command line) requires self-defined environment variables
Location variable:
$1 $2...
Special Data
$? : Return Value of the execution status of the previous command
Program execution may have two types of return values.
Program Execution result
Code returned from the program status (0-255)
0: Correct
1-255: execution error 127, system reserved
/Dev/null software device bit bucket, data black hole
Undo variable
Unset VARNAME
View the current shell variable:
Set
View the environment variables in the Current shell
Printenv env export
Add string variable
Script: the source program implemented by the command flow control mechanism based on actual needs.
Shebang: Magic number
#! /Bin/bash
# Comment row, not executed
Nano fisrt. sh write script
Programming Language: machine language, assembly language, advanced language
Static language: compiled language strong type (variable) is converted into executable format in advance
Dynamic Language: interpreted and executed on the fly
Asp. Php, python Shell
Variable: memory space, name
Memory: the storage unit.
Process:
1 + 100
Variable type: Determine the data storage format and length in advance
Character
Value
Integer
Floating Point: 11.23 1.123*10 ^ 1,
Logic: 1 + 1> 2
Logical operation: And, or, not, exclusive or
Bash: script interpreter
Programming capability:
Script Programming
Condition judgment
If the user does not exist
Add a user to the password and the user is successfully added
Otherwise
Show if not, not added
How to implement conditional judgment in Bash
Condition judgment type:
Integer Test
Character Test
File Test
Conditional test expression:
[Expression]
[[Expression] keywords
Test expression
Integer comparison (binocular operation ):
-Eq: test whether two integers are equal: $ A-eq $ B
Variable name: it can only contain letters, numbers, and underscores. It cannot start with a number.
It should not be the same as the existing environment variable in the system
It is best to be knowledgeable
-Ne: test whether two integers are unequal: unequal, true; equal, false;
-Gt: test whether one number is greater than the other. If the value is greater than true, otherwise the value is false.
-Lt: test whether one number is smaller than the other.
-Ge: greater than or equal
-Le: less than or equal
The logical relationship between commands:
Logic and: & when the first condition is false, the second condition does not need to be judged. The final result already exists. When the first condition is true, the second condition must be judged.
Logic or: |
Condition judgment and control structure
Single branch if statement
If judgment condition; then
Statement1
Statrment2
Fi
If statement with two branches;
If judgment condition; then
Statement1
Statement2
Else
Statement3
Statement4
Fi
How to perform arithmetic operations in shell
A = 3
B = 6
Let C = $ A + $ B
2. $ [arithmetic expression]
C = $ [$ A + $ B]
3. $ (arithmetic expression ))
C =$ ($ A + $ B ))
4. expr arithmetic expression. There must be spaces between the operands and operators in the expression, and commands must be used to reference
C = 'expr $ A + $ B'