当前位置:网站首页>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
边栏推荐
- what? Does the multi merchant system not adapt to app? This is coming!
- 2787: calculate 24
- Baidu interview question - judge whether a positive integer is to the power of K of 2
- [crawler knowledge] better than lxml and BS4? Use of parser
- Is it safe for Hengtai securities to open an account?
- Overview and installation of scientific computing toolkit scipyscipy
- [feature construction] construction method of features
- About the acid of MySQL, there are thirty rounds of skirmishes with mvcc and interviewers
- Defects of matrix initialization
- How about Urumqi Shenwan Hongyuan securities account opening? Is it safe?
猜你喜欢

Mysql database query is so slow. Besides index, what else can it do?
![[advanced data mining technology] Introduction to advanced data mining technology](/img/93/cb5ee07bff50662ad2496ca2bb39da.png)
[advanced data mining technology] Introduction to advanced data mining technology

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

Five common misuse of async/await

MySQL - multi table query - seven join implementations, set operations, multi table query exercises
![[basic data mining technology] KNN simple clustering](/img/df/f4a3d9b8a636ea968c98d705547be7.png)
[basic data mining technology] KNN simple clustering

Brand new: the latest ranking of programming languages in July

Lenovo Filez helps Zhongshui North achieve safe and efficient file management

A simple method of converting SVG to PDF

Five digital transformation strategies of B2B Enterprises
随机推荐
Strong reference, weak reference, soft reference, virtual reference
Drawing library Matplotlib drawing
[shallow copy and deep copy], [heap and stack], [basic type and reference type]
Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
Is there any capital requirement for the online account opening of Ping An Securities? Is it safe
How to gracefully realize regular backup of MySQL database (glory Collection Edition)
Redis (12) -- redis server
Put apples
One bite of Stream(6)
Detailed explanation of ThreadLocal
Alibaba cloud and parallel cloud launched the cloud XR platform to support the rapid landing of immersive experience applications
About the acid of MySQL, there are thirty rounds of skirmishes with mvcc and interviewers
【MLFP】《Face Presentation Attack with Latex Masks in Multispectral Videos》
MySQL - multi table query - seven join implementations, set operations, multi table query exercises
Mysql database commands
Problems with SQLite compare comparison tables
class file has wrong version 55.0, should be 52.0
Eight transformation qualities that it leaders should possess
Defects of matrix initialization
Es+redis+mysql, the high availability architecture design is awesome! (supreme Collection Edition)