当前位置:网站首页>Shell script - string
Shell script - string
2022-07-01 08:47:00 【Little snail's way】
character string (String) It is a combination of a series of characters . The string is Shell One of the most commonly used data types in programming ( Besides numbers and strings , There are no other types ).
Strings can be made of single quotes ' '
Surround , You can also use double quotes " "
Surround , You can also use no quotes .
String example
str1=jack
str2="rose"
str3='100'
The difference between the three forms
- By single quotes
' '
Surrounded string :
- Any character will be output as it is , Using variables in it is not valid .
- Single quotation marks... Cannot appear in a string , Even if you escape single quotation marks .
- By double quotation marks
" "
Surrounded string :
- If it contains a variable , Then the variable will be resolved ( Get the value of the variable ), Instead of outputting it as it is .
- Double quotation marks can appear in the string , As long as it is escaped .
- A string that is not surrounded by quotation marks
- Variables in strings that are not surrounded by quotation marks are also parsed , This point and double quotation marks
" "
The surrounding string is the same . - No spaces in the string , Otherwise, the string after the space will be parsed as other variables or commands .
Script
#!/bin/bash
name=jack
str1= My name is $name
str2=" There's a personal \" name \" It's called $name"
str3=' My friend's name is $name'
echo $str1
echo $str2
echo $str3
Output :
My name is jack
There's a personal " name " It's called jack
My friend's name is $name
str1 It contains $name
, It is resolved to a variable name References to .
str2 Contains quotation marks , But it was escaped ( By backslash \ The beginning indicates the escape character ).str2 It also includes $name
, It is also resolved as a variable name References to .
str3 It also includes $name
, But only as ordinary characters , Does not resolve to a variable name References to .
Get string length
The specific method is as follows ,${#string_name}
,string_name Represents the string name .
The code is as follows :
#!/bin/bash
name=jack
echo ${#name}
Output :
4
边栏推荐
- Shell脚本-echo命令 转义符
- 集团公司固定资产管理的痛点和解决方案
- The use of word in graduation thesis
- Foundation: 3 Opencv getting started images and videos
- C语言学生信息管理系统
- SPL installation and basic use (II)
- Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
- Nacos - Configuration Management
- 电脑小技巧
- Software Engineer Interview Question brushing website and experience method
猜你喜欢
What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
AVL树的理解和实现
Li Kou 1358 -- number of substrings containing all three characters (double pointer)
明明设计的是高带宽,差点加工成开路?
factory type_id::create过程解析
电视机尺寸与观看距离
factory type_ Id:: create process resolution
Advanced C language pointer (Part 2)
15Mo3 German standard steel plate 15Mo3 chemical composition 15Mo3 mechanical property analysis of Wuyang Steel Works
随机推荐
【C】 Summary of wrong questions in winter vacation
截图小妙招
如何做好固定资产管理?易点易动提供智能化方案
日常办公耗材管理解决方案
SPL Introduction (I)
Memory size end
The use of word in graduation thesis
factory type_ Id:: create process resolution
How can enterprises and developers take the lead in the outbreak of cloud native landing?
Li Kou 1358 -- number of substrings containing all three characters (double pointer)
MATLAB【函数求导】
Input标签的type设置为number,去掉上下箭头
Shell脚本-case in 和正则表达式
IT 技术电子书 收藏
Shell脚本-变量的定义、赋值和删除
大型工厂设备管理痛点和解决方案
《单片机原理及应用》-片外拓展
中考体育项目满分标准(深圳、安徽、湖北)
3. Detailed explanation of Modbus communication protocol
Matlab [function derivation]