I just got started with Linux development and recently encountered the problem of calling shell scripts in Java. I found a method suitable for cainiao-level development, as described below:
Add # In the first line of the shell script to be run
Have you ever encountered such a situation: from the remote Linux environment of the software, you have compressed a large pile of files into a .tar.gz file, which has not been completed for half an hour in a row. Then, suddenly you are disconnected
Struct point {int X, Y; point () {} Point (int xx, int YY) {x = xx; y = YY;} point operator-(point const & B) const {return point (x-b.x, y-b.y);} int friend operator * (point a, point B) {return f_abs (. x * B. y-a.y * B. x) ;}int len2 () {return x
The syntax format of case is as follows:Case VaR inExp-1) command body 1 ;;Exp-2) command body 2 ;;...*) Command body ;;Shell calculates the value of the variable VAR, and compares the result with the formula exp-1 and exp-2 until a matching formula
It usually takes a long time to run some monitoring tools or disk check tasks in shell.ProgramThe sighup signal is received to terminate the operation. Obviously, this is not the case.The nohup and bash built-in commands disown can solve this
1. Use multiple commands
To run multiple commands together, you only need to input them to the same line, separated by semicolons.
Ex: data; WHO 2. Create a script file
(1) #! /Bin/bash is the first line
(2) # Add comments.
(3) Each line
If you have multiple NICs, you must specify the NIC name because the IP address is related to the NIC.
The method for getting the IP address of the specified Nic is:
Ifconfig eth0 | sed-n "p" | awk '{print substr ($ )}'
"Eth0" indicates the
Author: Wang Shanshan,Hua Qing vision embedded college lecturer.
I. Differences and usage between system variables, user variables, and environment variables in shell:
Shell has the following basic types of variables:
1) environment variables
The following are all from network collection. I sorted it out myself and only sorted out some things that I was not familiar with before, but will be used now:I. Definition of variables in makefile:1. recursive expansion: the variables defined by
In actual project development, there are many applications that retrieve data from the database. The general solution is to write a data retrieval method. the SQL script is then called and obtained in the shell program. In fact, these two steps can
Opening Remarks: here we will record some common bash commands, for example, memo and hope to help others solve some problems.
1. Check whether the file exists
if [ -f ./foo.txt ]then echo the file existsfi
2. Check whether the directory exists
I. Input and Output 1. standard file descriptor
Each process can have a maximum of nine open file descriptors: 0 -- stdin, 1 -- stdout, 2 -- stderr.
(1) stdin
For terminals, stdin is the keyboard.
When the input redirection symbol (
(2)
Write shell code
The following is a shell C program shellcode. C: (this article takes Linux on intelx86 as an example)
Void main (){Char * name [2];
Name [0] = "/bin/sh ";Name [1] = NULL;Execve (name [0], name, null );}
Compile it as the Execution
Chapter 2 shell Basics
1. Which two files are used during shell initialization?
/Etc/profile, which contains the shell initialization information required by all users in the system
. Profile, whether it is in the user's starting directory. The
6th hours Process
6.1 start a process
In UNIX, whenever a command is executed, it creates or starts a new process.
For example, when you use the LS command to list a directory, a process is started.
The operating system uses a five-digit ID called
Lesson 6 variables
Part 2 shell programming
7.1 define variables
Format: Name = value # Note: there cannot be spaces on both sides of the equal sign!
This is different from other scripting languages: value can be defined as a variable value without
The eighth Condition Statement 10.1.1 is a simple if statement $ if 3> 2; then Echo 3; else Echo 2; FI # This is the form of $ cat> test in the command line. sh #! /Bin/shif 3> 2; thenecho 3 elseecho 2fi10. 1.2 use the test format: Test expression
12.3 option analysis in shell script
The first method is to use the case statement for manual processing.
Method 2: Use the getopts command to analyze the options
Syntax format:
Getopts option-string variable
Option-string is a string that contains
14th class hour Functions
14.1 create and use functions
Format: Name () {list ;}
An important feature of Shell functions is that they can be used to replace binary executable files or shell built-in commands with the same name.
For example:
CD () {
Instance
General programming steps
Now let's discuss the general steps for writing a script. Any excellent script should have help and input parameters. And write a pseudo script (Framework. Sh) that contains the framework structure required by
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.