4) Functions
If you write a bit more complexProgram, You will find that the sameCodeAnd you will also find it much easier if we use a function. A function looks like this:
Functionname ()
{
# Inside the body $1 is the first argument given to
During shell programming, you often encounter the problem of getting the file name and file suffix. The general solution is as follows:
1 # Code 2 file = " thisfile.txt " 3 echo " filename :$ {file %. *} " 4 echo "
1. When the crontab command is executedProgramIt is a little different and should be noted. For example, PS aux | grep File
If the statement is executed directly in shell, the search scope is only the process currently executed in top, and the
Latency functions in Linux Shell
Latency processing is often required in Linux shell scripts.
Therefore, sleep or usleep functions are often used.
The difference between sleep and usleep is as follows:
Sleep: the default unit is seconds.
What is data stream redirection?
What is data stream redirection? This should be explained by the running result of the command! Generally, if you want to run a command, it will usually be like this:
Figure 5.1.1 data transmission
If there is no body file, use echo to directly extract the body, for example:
Echo "this is content" | mutt-s "this is subject"-A/path/Yourfile abc@local.domain-C bbb@local.domain
If there is a body file, use
CAT/path/contentfile | mutt-s "this
In Windows shell scripts, if you want to use the current date and timeCompositionFile name. You can use the following method:
First obtain the string of the current date and time;
Separate the desired characters;
Finally, splice the file
1. for arithmetic operations. There are several assignment methods:
Let a = 1 + 2Echo $
A = $(3 + 3 ))Echo $
A = $ [4*4]Echo "$"
Set $ [A = 5*5]Echo "$"
2. Determine whether a directory exists:If [-d "$ (PWD)/.../candpointer"]; thenEcho "
Original article link
Before using sshpass, see
Shell script Automation
Automatic SSH logon methods
1. Automatic ssh/SCP Method =
A is a local host (that is, a machine used to control other hosts );B is the remote host (
In the Linux Shell environment, input and output redirection is supported, expressed by symbols . 0, 1, and 2 indicate the standard input, standard output, and standard error information output, which can be used to specify the standard input or
1. I want to know which shells have been installed on my machine?
You can view the following two methods:
First:
[Rocrocket @ wupengchong ~] $ CHSH-l
/Bin/sh
/Bin/bash
/Sbin/nologin
/Bin/zsh
Second:
[Rocrocket @ wupengchong ~] $ CAT/etc/shells
/Bin/
Shell Structures are divided into three categories: sequential structure, branch structure, and cyclic structure.
1. If statement
Syntax format:
IfThenFi
If the return value of the last command in statement sequence a is 0, execute the command
Features required last time ~ The problem can be solved only by asking for advice on csdn ~ Hey hey ~
Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->#! /Bin/sh
Voicedir = "/var/www/html /"
History display command history list
← (Ctrl + p) display the previous command
Hide (Ctrl + n) display the next command
! Num: The num command in the History list.
!! Run the previous command
!? String? Execute the latest command containing string
1. ftp automatically logs in to batch download files.
Copy codeThe Code is as follows: ##### migrate/home/data from the ftp server to the local/home/databackup ####
#! /Bin/bash
Ftp-n Open 192.168.1.171
User guest
Shell scripts can read data in the following ways:1. keyboard input, default2. Read from the file3. Pipeline Command Transmission
Echo functions:\ C: Do not wrap\ F: Paper Feed\ T: Skip\ N: line feed\ Indicates escape, for example: "\"/dev/rmt0 "\"
1. Introduction to file typesLinux mainly includes the following seven file types: d directory-common file l symbol link s socket file B device file c character device file p name pipe File
2. Regular ExpressionRegular Expressions are very important
The following are Shell Study Notes for 1-2 days:
--------- I am a separator ---------
Hardware is executed, and operations are performed between the kernel and hardware.
Command parser.
Shell script Components
System commands
Text processing
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