当前位置:网站首页>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
边栏推荐
- None of the most complete MySQL commands in history is applicable to work and interview (supreme Collection Edition)
- Rce (no echo)
- [summary of Feature Engineering] explain what features are and the steps of feature engineering
- Static & dynamic & file address book
- Overview and installation of scientific computing toolkit scipyscipy
- Summary of yarn capacity scheduler
- Codeforces Round #808 (Div. 2)(A~D)
- 96. Strange tower of Hanoi
- Drawing library Matplotlib styles and styles
- Ch single database data migration to read / write separation mode
猜你喜欢

One bite of Stream(7)

Five common misuse of async/await

Ch single database data migration to read / write separation mode

class file has wrong version 55.0, should be 52.0

C synchronous asynchronous callback state machine async await demo

ma.glasnost.orika. MappingException:No converter registered for conversion from Date to LocalDateTime

Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)

【MLFP】《Face Presentation Attack with Latex Masks in Multispectral Videos》

Information System Project Manager - Chapter 10 project communication management and project stakeholder management
Hilditch refinement (implementation I)
随机推荐
250 million, Banan District perception system data collection, background analysis, Xueliang engineering network and operation and maintenance service project: Chinatelecom won the bid
With this PDF, I successfully got offers from ant, jd.com, Xiaomi, Tencent and other major manufacturers
ma.glasnost.orika. MappingException:No converter registered for conversion from Date to LocalDateTime
[image processing] pyefd.elliptic_ fourier_ How descriptors are used
OSI的体系结构,以及各层协议
[SOC] the first project of SOC Hello World
Acwing 94. recursive implementation of permutation enumeration
A very useful log4net logging library
[development tutorial 6] crazy shell arm function mobile phone - interruption experiment tutorial
[Development Tutorial 4] open source Bluetooth heart rate waterproof sports Bracelet - external flash reading and writing
Let's make a nice monthly temperature map of China with ArcGIS
Case analysis of building cross department communication system on low code platform
[jzof] 05 replace spaces
Drive subsystem development
中信证券股票开户怎么样安全吗
93. Recursive implementation of combinatorial enumeration
One bite of Stream(6)
Es+redis+mysql, the high availability architecture design is awesome! (supreme Collection Edition)
Using gcc to avoid stack smash attack
climb stairs