If the variable is null, you can use: = to set a default value. Syntax:
$ {Var: = defaultvalue}
Example:
Enter the following command in terminal:
Jubincn @ Ubuntu :~ $ Echo $ {Bank: = ICBC} icbcjubincn @ Ubuntu :~ $ Echo bankicbcjubincn @
Preface shell script writing can be modularized or functional. For example, test1.sh can complete an independent function and test2.sh can also complete an independent function, but test1.sh is required as the premise. Therefore, in order to save
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
From: http://aaronw.me/static/779.html
This is the first method: (punctuation will be missed)#! /Bin/Shawk 'in in {hextab = "0123456789abcdef" for (I = 1; I This is the second method:#/Bin/Shawk 'in in {for (I = 0; I 1); printf "% s", substr (I, 1,
Conditional Criterion
Just talk about 『Program", Then the conditional criterion, that is, the criterion" If then ", must be learned! Because in many cases, we have to determine how the program should proceed based on certain data.
If... then
#! /Bin/bash # script filename: addbook. bsh # comment: add info to datafile # datafile: Conn. dat # initialize the variables datafile = "Conn. dat " name =" " phone =" " address =" " email =" " # Check in argument list then add info to
Preface
The time complexity of determining whether an element exists in an array is generally O (N), because the common practice is to traverse the array and check whether the data to be searched exists.
Here is a method for determining
Reprint: http://www.51testing.com /? Uid-225738-action-viewspace-itemid-218002
ShellProcessing
StringMethod (for future reference)
1. Construct a string
Direct Construction
Str_zero = Hello
Str_first = "I Am a string"
Str_second =
1. Get the return value of Command Execution
?
2. Get the return value of Script Execution
#!/bin/bashecho "A test."exit 0
Echo $ ?, Output: 0
3. Execute programs in the background in Linux
In Windows, use the start command and specify the/B
Parameters:% H (expressed in-23 ).% I hour (expressed as 01-12 ).% K hour (expressed as 0-23 ).% L hour (expressed as 0-12 ).% M minutes (expressed in-59 ).% P am or PM.% R time (including hour, minute, and second, expressed in 12 hours AM/PM ).% S
This afternoon, I was busy writing a small script one afternoon. There were a lot of errors in the middle. I found the details about sort and uniq, and I found some minor mistakes in writing the script myself, programming is a strictly prohibited
Color is selected by adding a special sequence --Basically"/E ["And"M"Between numeric values. If more than one numeric code is specified, separate them with semicolons.Echo-e "/E [31; 40 m"
First digit (31)Foreground color(Red); The second digit is(4
Command line parameters when running the script, as shown in figure
./myscript.sh -a -b arg
In scripts, case statements are usually used for processing. My personal favorite practice: first try to use long parameter names (short parameter names are
Usage of Linux Shell scripts in character Text Processing
Author: Yu Chao email: yuchao86@gmail.com
Shell may not be as powerful as perl, but it is also very useful for some special purposes.
Let's look at the following example:
[Yuchao @
Operator
Description
Example
File comparison operator
-EFilename
IfFilenameYes, true
[-E/var/log/syslog]
-DFilename
IfFilenameIs a directory, it is true
[-D/tmp/mydir]
-FFilename
IfFilenameIs
> Append
> Overwrite
> & Set the previous storage location to the next storage location
P.S.: Of course, there is still an inverse
0 standard input
1 standard output
2 standard errors
Example:
ls /usr/tmp 2> err.file
Write the error generated
1. http://edsionte.com/techblog/archives/3712 echo and backslash
Group records:2. This is only a variable. Double quotation marks will prevent shell tokens from echo "a B" and echo a B.
3 --------
4 "a B" is a parameter of echo, while echo a B is
It may have been a long time to stay in the shell, so that the current world is almost confused.This is the case when developers are busy with development and do not know the changes in the environment around them all day long. Maybe in
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