In Linux, shell is a commonly used tool. In Red Hat Linux, we usually use B shell or bash. In Shell, we always want to set some environment variables or other initialization operations when opening this shell. But how can we do this? Although we can
shell recognition: built-in commands, Shell functions, and external commands: (1) the built-in command is the command executed by the shell itself. some commands are built-in because of their necessity. For example, if CD is used to change
1. Basic Knowledge
CAT/etc/ShellCHSH/bin/tcshEmacs = Vi?PdkshZsh
B C KPID is 1 not 0
Home variables exists in passwd, And the last entry of passwd is sh.
PS-Ef svr4PS au for BSD/Linux ps
Echo $ statusEcho $?
EUID // can be changed, like
BASH Shell is the default shell in Linux. It can be supplemented by tab, and historical commands such as up/down key switching are easier to use than the default KSh shell in Aix (most Unix systems.
All Linux software that can be installed under
I. Use of local variablesLocal variables act only in this shell, just like local variables. It does not affect variables in other shells.
1. Show variable valuesYou can use the echo command. Note that you must add the $ symbol before the variable
Okay. Run this script and you will understand it.#! /Bin/bash
Until
[
$
#-EQ 0]
Do
Echo
"$ @"
Shift
Done
See the role. When shift (without parameters) is run each time, a parameter is destroyed and the subsequent parameter is moved forward.
in command line (that is, start-run-input cmd) mode, if you enter the ADB shell command, two errors are generally reported. One is that" ADB is not an internal command or an external command, it is neither a running Program or a batch file. The
1. The method for modifying the language family is:
[Root @ test root] # lang = en (specify other syntaxes as needed, such as C)
[Root @ test root] # export Lang
Linux VI deletes all specified characters
Press ESC to return the command
Use the if statement to determine parameters in shell programming
-B. returns true if the file exists and is a block file.
-C: returns true if the file exists and is a character file.
-D. If pathname exists and is a directory, true is returned.
-E:
The parentheses in shell have their special usage, which are summarized as follows:1. brackets after the symbol $The value of $ {A} variable A can be omitted without ambiguity.$ (CMD) command is replaced and the result is the output of Shell Command
In the past, when I was writing code, I encountered a problem with the file path. for example, extract the directory or file name of the file path and determine whether the directory or file exists. every time you encounter such a problem, you
#! /Bin/shwebsite [0] = 'zufang .hfhouse.com/chuzu/' # Website 1 mobile [0] = '000000' # Website 1 mobile number website [1] = 'oldhouse .hfhouse.com/chushou/' # Same as 2 mobile [1] = '000000' # Same as above 2 # and so on, if there are too many
Date + % s can get UNIX timestamp;Use shell to convert time strings and timestamps:Date-d "00:00:00" + % s output format: 1287331200The time stamp can be converted to a string as follows:Date-d @ 1287331200 "+ % Y-% m-% d" output format:
Shell condition tests are usually used in control flow structures such as for, while, until, and if to determine the relationship between the object's related properties or variables.
Usage of conditional test: Test
Result: If the value is true, 0
Shortcut Operators
If you are familiar with the C language, you may like the following expressions:
[-F "/etc/shadow"] & echo "This computer uses shadow passwors"
Here & is a shortcut operator. If the expression on the left is true, execute the
This article is the fourth chapter of Learning the bash Shell 3rd Edition, Basic Shell Programming, but we will not limit it to this.
Run the shell script program
A script containing shell commands is a shell program, such as. bash_profile. We can
Variables and strings
Bash shell does not have the so-called "Data Form" unless the built-in declare is used to specify the variable type. In Bash shell, there is only one data type: A string consisting of Characters
Use it without having to go
Process management and work control
Use of ps, top, and htop commands
Transmit signal
You can use the kill command to manage the signal sent by the process. The basic principle for managing processes is
1. First, send a signal to the process so that
Arithmetic Operations and Comparison
1. Operator (let identifier)
+ Addition-subtraction * multiplication/division ** power operation 3 let "z = 5 ** 3" % modulo bash $ expr 5% 3
2. comparison operator (note that a space is required between []
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