码迷,mamicode.com
首页 > 系统相关 > 详细

shell 字符串

时间:2016-02-22 23:23:46      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

字符串可以分为单引号,双引号,也可以不用引号

单引号

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}

shell 字符串

标签:

原文地址:http://www.cnblogs.com/techdreaming/p/5208447.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!