Preface I haven't written a shell script for a long time. Today I can see such a requirement in the group as follows: I also reviewed the shell script and wrote it easily.
ProgramAfter testing, I basically passed the train of thought.
First,
Although he does not know who Lu Jun is, his book is indeed easy to understand and has the meaning of training materials..
Linux Shell programming started from UNIX and was presented as a human-computer interaction tool in the early days. After
The test statement must have spaces before and after the equal sign, and there can be more than one space. To promote it, there must be no spaces before and after the equal sign of the value assignment statement, non-assignment statements require
I want to perform frequent operations on a file. To obtain the values of different columns in each row, I know the method isWhile read lineDoEcho $ Line | awk '{print $1}' # obtain the value of the first column in each rowEcho $ Line | awk '{print $2
Shell script:#! /Bin/Bash must pass the first line #! To specify the Current Shell
I. variables:"": Allows you to reference values of other variables using the $ symbol.'': Other variables cannot be referenced. $ is considered as a normal
The source command can load another script in one script. The following is an example:
First, we define a function script named myfunc. Sh, as follows:
#! /Bin/bashFunction Square{Local tempLet temp = $1*$1The sum of squares of Echo "$1 is: $ Temp"
We encountered the following problems during package packaging using Linux shell scripts:
Tar: removing leading '/' from Member names
Shell Content
#! /Bin/sh
Pkg_dir =$ {PWD}/release
Pkg_name1_release.tar.gz
Tar-zvcf $ {pkg_name }$ {pkg_dir}
From: http://standalone.javaeye.com/blog/511101
1. Use the shell variable $ randomEcho $ random
2. Use Random Functions of awkAwk 'in in {srand (); print rand ()}'
3. Use the System Device File/dev/random and/dev/urandomDd If =/dev/random | OD-
You often need to switch to a common directory, but the path is long and hard to remember. You want to use a script to enter the directory, but it will never change .......
Cause analysis:
When the script is executed, only a sub-process is
I. RequirementsWhenever you create, delete, or rename a folder/file in the Explorer window, or insert and remove a mobile storage, Windows can always update all its views very quickly. Sometimes our program also needs this feature so that our
I. Basics
We define a variable (there cannot be spaces on both sides of the equal sign)
Filepath =/var/home/SSSFilefilename = test001
When referencing this variable, we can directly use the variable name following $.
For example, $ filepathYou can
$ @ Refers to all command line parameters. Each parameter is enclosed ""
$ * Indicates all command line parameters
The following procedure:
Test1.sh
-------------------
Sum = 0For VaRIn "$ @"DoLet sum = sum + $ VaRDoneEcho "sum = $
Go to: http://goward.jimdo.com/2010/06/15/linux-shell%E5%90%84%E7%A7%8D%E5%BC%95%E5%8F%B7%E7%9A%84%E7%94%A8%E6%B3%95/
The difference between these characters is how they affect variables (such as $ name) and shell commands (such as date ). For any
Common scripts in Linux include bash and shell.
1
#!/bin/bashecho "hello bash" #display one message
Save the preceding content as a text file named me. The extension is arbitrary, but. Sh is often used as the extension.
Run the command chmod A + x
Linux bash calculator is easy to use, at least it is easier to be lazy.
How:
1. Use the command line# Scale indicates the exact number of digits of a floating point.[Root @ hostname ~] # BCBC 1.06Copyright 1991-1994,199 7, 1998,200 0 Free
Command line parameters,
Positional Parameter
$0Complete program name(BasenameCommand to remove the path)
$1The first parameter, exceeding9Hour$ {10}
$ #Number of parameters
$ *All parameters in the command line, as a word
$ @All parameters in the
I. Shell Condition Statement (if usage)
If statement structure [if/then/Elif/else/FI]
If condition test statement
Then
Action
[Elif Condition
Action
Else
Action
]
Fi
If you are not clear about the conditional test statement, refer
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
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