歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> shell 字符串

shell 字符串

日期:2017/3/2 17:16:08   编辑:SHELL編程
字符串可以分為單引號,雙引號,也可以不用引號

單引號

str='this is string'

單引號字符的限制:

單引號中的任何字符都會原樣輸出,單引號中變量是無效的

單引號中不能出現單引號

雙引號:

str=“my name is ${name}”

雙引號字符的優點:

雙引號中可以有變量

雙引號中可以出現轉移字符

拼接字符串

your_name="qinjx"
greeting="hello, "$your_name" !"
greeting_1="hello, ${your_name} !"

echo $greeting $greeting_1

獲取字符串的長度

str=“abcd”

echo ${#str}

提取子字符串

str=“this is my student”

echo ${string:1:3}
Copyright © Linux教程網 All Rights Reserved