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}

posted @ 2016-02-22 22:49  努力,奋斗  阅读(143)  评论(0编辑  收藏  举报