当前位置:网站首页>Shell introduction and variable definition
Shell introduction and variable definition
2022-07-24 21:32:00 【Test_ the_ rookie】
One 、 What is? shell
shell It's based on C Language development program .shell It's a command language , Another programming language .
Two 、 frequently-used shell
frequently-used shell Yes bash、sh、zsh. It's usually used bash.
3、 ... and 、shell Variable definition rules
1. When defining variables , Variable name and equal sign 、 There cannot be a space between the equal sign and the value .
2. Variable names can only use letters 、 Underline 、 Numbers , And can only start with letters and underscores
3. There cannot be spaces between variable names , have access to "_" Instead of .
4. When there are spaces in the variable value , You need to use double quotes / Quotation marks .
Four 、 Use of variables
1. When using variables , Need to use $ Symbol , Such as :

Be careful : When using variables ,{} It's not necessary ,{} The function of is to determine the boundary of variables , When variables are followed by others code when , Need to add {}, In this way, the program can correctly identify the boundary of variables .
2. Define a read-only variable : Use readonly Read variables , Usage such as ===》readonly Variable name
3. Delete variables : Use unset You can delete variables , But you cannot delete read-only variables

4. Variable type ( Just to understand ):
local variable : Only in the current shell Use in , Other shell cannot access .
environment variable :Linux A variable of its own
shell Variable :shell Special variables for program settings
Be careful : When you want the child process to access the variables of the parent process , Need to use export, Export private variables .

5、 ... and 、shell String in
1.shell Strings in can be declared with single or double quotation marks .
2. String declared in single quotation marks , When there are variables in it , Unable to get the value of the corresponding variable .
3. Strings declared in double quotation marks can use variables and escape characters .

4. Get string length :echo ${# String name }
5. Extract string :echo ${ String name :m:n} m: Represents the starting coordinate ,n Represents the extracted length .
6. String content substitution :
6.1 Replace a matching value :echo ${ Variable name / Original value / The new value }
6.2 Replace all matching values :echo ${ Variable name // Original value / The new value }

7. Check the position of the specified character in the string :( Be careful ! This is not a single quote , It's a back quote “`”)

6、 ... and 、 Define an array
1.shell Only one dimensional arrays are supported
2. The grammar is : Array name =( value 1 value 2 .... value n), Space between each value .
3. Get the specified element in the array :echo ${ Array name [ Subscript of corresponding element ]}
4. Gets the length of the array :echo ${# Array name [*]}

-------------------------------------------------------- No end for learning
边栏推荐
- Thank Huawei for sharing the developer plan
- 【MLFP】《Face Presentation Attack with Latex Masks in Multispectral Videos》
- 01_ UE4 advanced_ PBR material
- [jzof] 06 print linked list from end to end
- findContours
- Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)
- MQ release confirmation
- Lecun proposed that mask strategy can also be applied to twin networks based on vit for self supervised learning!
- Together again Net program hangs dead, a real case analysis of using WinDbg
- Spark related FAQ summary
猜你喜欢

Together again Net program hangs dead, a real case analysis of using WinDbg

Codeforces Round #808 (Div. 2)(A~D)

MQ release confirmation

How does redis realize inventory deduction and prevent oversold? (glory Collection Edition)

C synchronous asynchronous callback state machine async await demo

Solution: 2003 cant connect to MySQL server on * * * * and use near 'identified by' * * * * 'with grant option' at

MySQL - multi table query - seven join implementations, set operations, multi table query exercises
![[basic data mining technology] exploratory data analysis](/img/0c/1b73098a589a2af398dd3cd9d62cd7.png)
[basic data mining technology] exploratory data analysis
![[record of question brushing] 16. The sum of the nearest three numbers](/img/b9/a78b72650e94c75ccbe22af1f43857.png)
[record of question brushing] 16. The sum of the nearest three numbers
![[advanced data processing technology] data filtering, advanced data filling, initial and advanced data transformation](/img/0c/70643343d73137926963013a4862d0.png)
[advanced data processing technology] data filtering, advanced data filling, initial and advanced data transformation
随机推荐
From front-line development to technical director, you are almost on the shelf
Shengbang security rushes to the scientific innovation board: Qianxin is its largest customer (55.87 million); Its three-year revenue is 460 million, net profit is 95.04 million, and R & D investment
Lazily doing nucleic acid and making (forging health code) web pages: detained for 5 days
Make good use of these seven tips in code review, and it is easy to establish your opposition alliance
[feature construction] construction method of features
Go language structure
C WinForm actual operation XML code, including the demonstration of creating, saving, querying and deleting forms
what? Does the multi merchant system not adapt to app? This is coming!
MQ release confirmation
Thank Huawei for sharing the developer plan
Today, there's a power failure for one day.... stop working for another day. Don't forget to study
Can century model simulate soil respiration? Practice technology application and case analysis of century model
RESNET interpretation and 1 × 1 Introduction to convolution
Opencv learning Day2
Volcano engine releases cloud growth solutions for six industries
Lecun proposed that mask strategy can also be applied to twin networks based on vit for self supervised learning!
怎么在中金证券购买新课理财产品?收益百分之6
Sword finger offer 15. number of 1 in binary
Which bank outlet in Zhejiang can buy ETF fund products?
[jzof] 04 search in two-dimensional array