您的位置:首页 > 运维架构 > Shell

shell 字符串

2016-02-22 22:49 309 查看
字符串可以分为单引号,双引号,也可以不用引号

单引号

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}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: