By default, the Ubuntu shell is installed with Dash instead of bash.Run the following command to view the sh details and confirm the corresponding ShellProgramWhich is:$ LS-Al/bin/sh
Dash is lighter and faster than bash. Bash is more commonly
Shell variables:(1) The variable and the variable content are connected with the equal sign "=;(2) The equal signs cannot be directly followed by space characters;(3) The variable name can only contain English letters and numbers, but cannot start
Based on the tutorials on the official website, the test is available.
Note that you must use the root permission to run the task.
#!/bin/bash# This script run the init command for opotimus pc;# Fedora 19;# run as the rootecho 'run as the root'yum
Chapter 2: using structured commands
Use the if-then statement
if commandthen commandsfi
If the exit status code of the command after if is 0, execute then.
Another Form
if command; then commandsfi
If-then-else statement
if commandthen
Shell sorting is a form of change in insert sorting. Because insert sorting compares each element and compares the current element with all the previous elements, in the worst case. Therefore, DL. shell proposed shell sorting in 1959, that is,
Some terminal shortcut keys:
CTRL + F
Forward one character
CTRL + B
Move one character behind
CTRL + E
Move to end of line
CTRL + L
Clear Screen
CTRL + d
Delete current
Shell scripts are used to record some exercise questions and shell scripts I have actually written here for learning and querying.
User input y or y ends
While Mode#! /Bin/bashRead-P "input you choice:" CWhile ["$ C "! = "Y"-a "$ C "! =
14 noglob variable
Set noglob to stop the wildcard function, that is, the image symbol *? [] {}~ And so on. All of the special functions they represent will be ineffective. It only represents general characters. The following is an example:
Shell script Learning (1): Shell variables and some common commands
Shell allows you to create variables to store data, but does not support basic data type variables (such as int, float .....), shell interprets any value assigned to a
The case statementthe case statement is good alternative to multilevel if-then-else-fi statement. It enable you to match several
Values against one variable. Its easier to read and write. Syntax:
case $variable-name in
From: http://www.cnblogs.com/hanyan225/archive/2011/10/06/2199652.html
There is no doubt about the strength of shell, which makes it easier for us to confuse us. For example, I have always thought that I am smart and cannot tell you clearly.In Shell,
Ls-l dir1 | WC-L.
1. While condition; do done // () [] Test2. Until is the same as above. It is executed only when the condition is not true.3. /Dev/null: Unix black hole. Used to clear the file CAT/dev/null> XX find-name a.txt 2>/dev/null4. Note:
Unix shell programming
Summary of some conditions
-B file: if the file exists and is a special block file, it is true.-C file: if the file exists and is a special character file, it is true.-D file: if the file exists and is a directory, it is true.-
If the command "Set-X" is added to the script file, each command executed after the set command and any parameters added to the command line (including the values of variables and variables) will be displayed. A plus sign (+) is added before each
#! /Bin/sh
# Filename: 2.sh
B = 9
E = 15
Tmpb = $ B
While [$ tmpb-Le $ E]
Do
Echo $ tmpb
# Tmpb = 'expr $ tmpb + 1' // OK
Tmpb = $ (expr $ tmpb + 1)
Done
After the script is executed, the output result is:
9101112131415
Note: The
To determine whether the variables in a script are empty, I wrote a shell script like this:
#! /Bin/sh
# Filename: Test. Sh
Para1 =
If [! -N $ para1]; then
Echo "is null"
Else
Echo "not null"
Fi
Then run the Script: test. sh uses
Special characters in Linux Shell
1. braces:
Usage 1: wildcard Extension
Eg: ls my _ {finger, toe} s
This command is equivalent to a combination of the following commands:
Ls my_fingers my_toes
For example: mkdir {usera, userb, userc}-{home, bin,
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