当前位置:网站首页>Getting started with shell Basics
Getting started with shell Basics
2022-06-30 14:01:00 【Upward Wolf】
One 、Shell Variable
1.1、 When defining variables , Variable name without dollar sign
- Only English letters can be used for naming , Numbers and underscores , The first character cannot begin with a number .
- No spaces in between , You can use underscores (_).
- You can't use punctuation .
- Out of commission bash Keywords in ( You can use help Command to view reserved keywords )
1.2、 The type of variable
local variable
- Local variables are defined in scripts or commands , At present only shell Valid in instance , other shell The program started cannot access Ask local variables .
environment variable
- All procedures , Include shell Program started , Can access environment variables , Some programs need environment variables to ensure their normal operation
Shell Variable
- shell Variables are derived from shell Special variables for program settings .shell Some of the variables are environment variables , Some of them are local variables
# Declaration of variablesname="zhangsan"# Variable callecho $nameecho ${name}# A read-only variable /bin/sh: NAME: This variable is read only.url="https://www.google.com"readonly urlurl="https://www.runoob.com"# Delete variablesunset name
Two 、Shell String
- Any character in a single quotation mark will be output as is , Variables in a single quoted string are invalid ;
- A single quotation mark cannot appear in a single quotation mark string , But in pairs , Use as string concatenation .
Double quotes :
- You can have variables in double quotes
- Escape characters can appear in double quotes
# Declaration stringstr1="hello world 1"str2='hello world 2'str3='hello world3# String splicing -- Double quotesname='sunwukong'name1="hello, "$name"" // It can be stitched togethername2="hello, ${name}" // It can be stitched together# String splicing -- Single quotation markspasswd='123456'passwd1='hello, '$passwd'' // It can be stitched togetherpasswd2='hello, ${passwd}' // Can't spliceecho $passwd2 # hello, ${passwd} !# Length of stringecho ${#email} // Gets the length of the stringecho ${email:1:4} // obtain email String from 1 Start , take 4 Characters ( The count of strings starts from )
3、 ... and 、Shell Array
- bash Supports one dimensional array ( Multidimensional arrays are not supported ), And there's no limit to the size of the array .
- The subscripts of array elements are 0 Numbered starting . To get the elements in an array, you need to use subscripts , Subscripts can be integers or arithmetic expressions , Its Value should be greater than or equal to 0.
# Define an array Parentheses are used to represent arrays , For array elements " Space " Symbol splitArray name =( value 1 value 2 ... value n)favs=(" football " " blue ball " " Table tennis " " The bowling ball ")# Read array ${ Array name [ Subscript ]}fav=${favs[1]}# Use @ The symbol can get all the elements in the arrayecho ${favs[@]}# Gets the length of the arraylength1=${#favs[@]}length2=${#favs[*]}
Four 、Shell Notes
- With # The first line is the comment , Will be ignored by the interpreter .
- Add one... To each line # Number to set multiline comment
#--------------------------------------------# This is a comment# author:# site:#--------------------------------------------##### Server configuration -start ############### Server configuration -end ###### Special multiline comments:<<EOFThe comment ...The comment ...The comment ...EOF:<<!The comment ...The comment ...The comment ...!notes : here EOF and ! It can be changed , But make sure the front and the back are the same
5、 ... and 、Shell Parameter passing
perform Shell Script time , Pass parameters to script , The format of obtaining parameters in the script is : $n, n Represents a number .

#!/bin/bashecho "Shell Pass parameter instance !";echo " File name of execution :$0";echo " The first parameter is zero :$1";echo " The second parameter is :$2";echo " The third parameter is zero :$3";# ./hello.sh 11 22 33 44
边栏推荐
- MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
- Introduction to two types of rxjs observable operators
- Basic syntax of unity script (1) - common operations of game objects
- 【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
- Publicity of the fourth batch of shortlisted Enterprises - annual Top100 smart Internet supplier selection
- 我如何才能保护我的私钥?
- 第四批入围企业公示——年度TOP100智能网联供应商评选
- [the path of system analyst] Chapter 5 Software Engineering (Agile Development)
- 科普达人丨漫画图解什么是eRDMA?
- ERROR: Cannot uninstall ‘PyYAML‘. It is a distutils installed project and thus we cannot accurately
猜你喜欢
正则系列之断言Assertions
This editor will open source soon!
【刷题篇】供暖器
[redis series] redis learning 16. Redis Dictionary (map) and its core coding structure
DeFi“钱从哪来”?一个大多数人都没搞清楚的问题
visualstudio 和sql
[observation] as the intelligent industry accelerates, why should AI computing power take the lead?
智慧运维:基于 BIM 技术的可视化管理系统
【科学文献计量】外文文献及中文文献关键词的挖掘与可视化
编程实战赛来啦!B站周边、高级会员等好礼送你啦!
随机推荐
可观测,才可靠:云上自动化运维CloudOps系列沙龙 第一弹
数字时代,XDR(扩展检测与响应)的无限可能
正则系列之断言Assertions
IM即时通讯应用开发中无法解决的“顽疾”
【刷题篇】供暖器
Assertions of regular series
Why can't the database table be written into data
Introduction to reverse commissioning - VA and RVA conversion in PE 04/07
golang模板(text/template)
Directory related commands
我如何才能保护我的私钥?
DNS resolution home network access public DNS practice
[scientific research data processing] [basic] category variable frequency analysis chart, numerical variable distribution chart and normality test (including lognormal)
[Title brushing] heater
Yousi College: Six Sigma is not just statistics!
[Title brushing] avoid flooding
编程实战赛来啦!B站周边、高级会员等好礼送你啦!
随着产业互联网的发展,有关互联网的落地和应用也就变得宽阔了起来
Simple understanding of the difference between get request and post submission
Lucky hash quiz system development (source code deployment) fun investment hash game play development (case requirements)