当前位置:网站首页>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
边栏推荐
- Input标签的type设置为number,去掉上下箭头
- Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling
- MySQL8.0学习记录17 -Create Table
- Shell脚本-read命令:读取从键盘输入的数据
- 长安链同步节点配置与启动
- Glitch Free时钟切换技术
- Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
- FreeRTOS learning easy notes
- MATLAB【函数求导】
- [untitled]
猜你喜欢

一文纵览主流 NFT 市场平台版税、服务费设计

1. Connection between Jetson and camera

Memory size end

Principle and application of single chip microcomputer - principle of parallel IO port

3. Detailed explanation of Modbus communication protocol

截图小妙招

Personal decoration notes

性能提升2-3倍!百度智能云第二代昆仑芯服务器上线

What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength

ARM v7的体系结构A、R、M区别,分别应用在什么领域?
随机推荐
明明设计的是高带宽,差点加工成开路?
Qt的模型与视图
It technology ebook collection
Nacos - Configuration Management
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
性能提升2-3倍!百度智能云第二代昆仑芯服务器上线
Advanced C language pointer (Part 2)
View drawing process analysis
Shell脚本-if else语句
NIO-零拷贝
Shell脚本-for循环和for int循环
中考体育项目满分标准(深圳、安徽、湖北)
Shell脚本-变量的定义、赋值和删除
Shell脚本-select in循环
Centos7 shell脚本一键安装jdk、mongo、kafka、ftp、postgresql、postgis、pgrouting
Shell脚本-echo命令 转义符
Advanced API
如何解决固定资产管理和盘点的难题?
Nacos - 配置管理
集团公司固定资产管理的痛点和解决方案