当前位置:网站首页>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
边栏推荐
- C语言学生信息管理系统
- Centos7 shell script one click installation of JDK, Mongo, Kafka, FTP, PostgreSQL, PostGIS, pgrouting
- 《单片机原理及应用》-片外拓展
- VSYNC+三重缓存机制+Choreographer
- Software Engineer Interview Question brushing website and experience method
- Only in China! Alicloud container service enters the Forrester leader quadrant
- MD文档中插入数学公式,Typora中插入数学公式
- Foundation: 3 Opencv getting started images and videos
- Matlab [function derivation]
- What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
猜你喜欢
V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code

How can enterprises and developers take the lead in the outbreak of cloud native landing?

MATLAB【函数求导】

《微机原理》-绪论

"Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis

factory type_id::create过程解析

What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?

猿人学第20题(题目会不定时更新)

Brief introduction to AES

基础:2.图像的本质
随机推荐
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
Foundation: 2 The essence of image
Shell脚本-while循环详解
《微机原理》-绪论
我想知道手机注册股票开户的流程?另外,手机开户安全么?
用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
Brief introduction to AES
3. Detailed explanation of Modbus communication protocol
Screenshot tips
[MFC development (16)] tree control
MATLAB【函数求导】
Installing Oracle EE
Introduction to R language
What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
如何做好固定资产管理?易点易动提供智能化方案
Insert mathematical formula in MD document and mathematical formula in typora
Matlab tips (23) matrix analysis -- simulated annealing
Properties of 15MnNiNbDR low temperature vessel steel, Wugang 15MnNiDR and 15MnNiNbDR steel plates
Guidelines and principles of did
Nacos - gestion de la configuration