当前位置:网站首页>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"
边栏推荐
- Idea implements hot deployment
- Server pressure troubleshooting top
- MySQL is slow to add indexes_ Why is your SQL so slow? Why is your MySQL index invalid?
- What is API
- [machine learning] machine learning from zero to mastery -- teach you to recognize handwritten digits using KNN
- [summary] 2021unctf Campus (cry & MISC)
- Differences between modems and routers (powercert animated videos)
- Uncover n core 'black magic' of Presto + alluxio
- 同花顺app是正规的吗?到底安不安全
- JS__ Inheritance mode, namespace, object enumeration__ Duyi
猜你喜欢
Cross project measurement is a good helper for CTOs and PMOS

After 20 days' interview, I finally joined Ali (share the interview process)
Why doesn't anyone read your hard-working blog? Do you really understand the skills of framing, typesetting and drawing?
Feature Engineering in simple terms – a practice guide based on openmldb (Part 1)

Flexible scale out: from file system to distributed file system
How to play one to many in JPA?

QT method of exiting application (exe)
![[nailing scenario capability package] company / Park Digital canteen](/img/72/eb3df1945532c4e7813e15f9cf90c5.jpg)
[nailing scenario capability package] company / Park Digital canteen

Xshell mouse configuration

Installing mysql8 under centos8
随机推荐
启牛学堂证券开户安全嘛?
Lantern Festival, learning at the right time! Novice training camp attacks again, learning buff continues to fill up
Decryption of APP parameters of a cross-border export e-commerce - dunhuang.com
STM32 self balancing robot project, with code, circuit diagram and other data attached at the end (learning materials and learning group at the end)
Summary of several methods for FPS calculation
Nine built-in objects of JSP and four scopes of Servlet
On ACM competition
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%
Xshell mouse configuration
Illustration tcp/ip - Chapter 1 and 2 Notes
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
股市小白通过网上进行股票开户安全吗?
Compile 6relayd using the cross compiler
同花顺炒股软件开户是合法的吗?安全吗
[distributed system design profile (1)] raft
The SH runtime directly reported an error syntax error near unexpected token ` $'. \r‘
Those high-frequency and real software test interview questions sorted out by the test director in 7 days, come to get
[deep learning series] - visual interpretation of neural network
[machine learning] machine learning from zero to mastery -- teaching you how to use decision tree to predict contact lens types
启牛证券开户安全嘛?