当前位置:网站首页>Shell syntax
Shell syntax
2022-06-25 21:15:00 【dengk2013】
#!/bin/bash
meaning : Set up current shell The script file adopts bash The parser runs the script code
Special variables :$n
Used to receive the parameters passed in when the script file is executed
$0 Used to get the name of the current script file
$1~$9, Means to obtain the first input parameter to the 9 Three input parameters
The first 10 Format of more than input parameters : ${ Numbers }, Otherwise, you can't get
Special variables :$#
grammar
$#
meaning
Get the number of all input parameters
Special variables :$?
grammar
$?
meaning
Used to get previous Shell Exit status code of the command , Or the return value of the function
Every Shell Command execution has a return value , This return value is used to indicate whether the command execution was successful
Generally speaking , return 0 Indicates that the command was executed successfully , Not 0 Delegate execution failed
A string of 3 Format differences
Use single quotes
''
String :Any character will be output as it is , Using variables in it is not valid
By double quotation marks " "
Surrounded string :
It contains variables , Then the variable will be parsed to get the value , Instead of outputting it as it is .
Double quoted substrings can also appear in the string , But you need to escape
3.
${# String variable name }
4.
String truncation Syntax
Format | explain |
---|---|
${ Variable name :start:length} | from string To the left of the string start Character start , Intercept to the right length Characters . |
${ Variable name :start} | from string To the left of the string start Characters begin to intercept , Until the last . |
${ Variable name :0-start:length} | from string To the right of the string start Character start , Intercept to the right length Characters . |
${ Variable name :0-start} | from string To the right of the string start Characters begin to intercept , Until the last . |
${ Variable name #*chars} | from string The first occurrence of a string *chars The position begins , Intercept *chars All characters on the right . |
${ Variable name ##*chars} | from string The last occurrence of the string *chars The position begins , Intercept *chars All characters on the right . |
${ Variable name %chars*} | from string The last occurrence of the string chars* The position begins , Intercept chars* All the characters on the left . |
${ Variable name %%chars*} | from string The first occurrence of a string chars* The position begins , Intercept chars* All the characters on the left |
alias Alias =' command ' You can specify rm -rf Alias to prevent deletion
unalias Alias
echo -e ' The string contains escape characters '
#!/bin/bash
read -p " Please enter a name , Age , hobby : " name age hobby
echo " full name :$name"
echo " Age :$age"
echo " hobby :$hobby"
边栏推荐
- [important notice] developer document update (12.13-12.19)
- How to solve the problem of flash write protection in STM32?
- What is DNS (domain name server)? (Powercert animated videos)
- Get parameters in URL
- [machine learning] machine learning from zero to mastery -- teach you to recognize handwritten digits using KNN
- Installing and configuring redis under Linux
- 2022 "gold, silver and four" is a must for job hopping. You must know 100 questions in 2022 intermediate and advanced Android interview to realize your big factory dream
- MySQL is slow to add indexes_ Why is your SQL so slow? Why is your MySQL index invalid?
- Lesson 1 Preparation
- Is flush app regular? Is it safe or not
猜你喜欢
05 configuring network parameters
[buucry] sensor (Manchester code)
Yunzhisheng atlas supercomputing platform: computing acceleration practice based on fluid + alluxio (Part I)
Feature Engineering in simple terms – a practice guide based on openmldb (Part 1)
Day 28/100 CI CD basic introductory concepts
Cvpr2020 | the latest cvpr2020 papers are the first to see, with all download links attached!
Working principle and experimental analysis of DHCP
C language dynamic memory allocation
HMS core actively explores the function based on hardware ear return, helping to reduce the overall singing delay rate of the singing bar by 60%
[deep learning series] - visual interpretation of neural network
随机推荐
Literals and type conversions of basic data types
Openocd compilation and installation
Cvpr2020 | the latest cvpr2020 papers are the first to see, with all download links attached!
What is an app circle of friends advertisement
01 network basics
Record some questions about MySQL (DNS reverse resolution in Linux)
Causes and solutions of unreliable JS timer execution
[nail scenario capability package] hospital visitor verification
Boomfilter learning
04 disk space management
[nailing scenario capability package] smart office phone
Live broadcast preview | front line experts invite you to talk: the value of data science enabling multiple application scenarios
Sqlmap for interface security testing
How to play one to many in JPA?
Working principle and experimental analysis of DHCP
Online yaml to XML tool
JS__ Inheritance mode, namespace, object enumeration__ Duyi
UDP Vs TCP (Powercert animated videos)
[nailing scenario capability package] video conference (official conference system)
银河证券靠谱吗?开证券账户安全吗?