字符串是shell编程中最常用最有用的数据类型(除了数字和字符串,也没啥其它类型好用了),字符串可以用单引号,也可以用双引号,也可以不用引号。单双引号的区别跟PHP类似。
1.your_name='qinjx'
2.str="Hello, I know your are \"$your_name\"! \n"
1.your_name="qinjx"
2.greeting="hello, "$your_name" !"
3.greeting_1="hello, ${your_name} !"
4.echo $greeting $greeting_1
1.string="abcd"
2.echo ${#string} #输出 4
1.#!/bin/bash
2.
3.your_name="onetwothree"
4.
5.echo $(#your_name)
1.[root@localhost lcr]# ./helloworld.sh
2../helloworld.sh:行5: 寻找匹配的 `)' 是遇到了未预期的文件结束符
3../helloworld.sh:行8: 语法错误: 未预期的文件结尾
1.string="runoob is a great site"
2.echo ${string:1:4} # 输出 unoo
1.#!/bin/bash
2.
3.your_name="runoob is a great site"
4.echo ${your_name:5:11}
1.b is a grea
2.[root@localhost lcr]# ./helloworld.sh
3.b is a grea
1.string="runoob is a great company"
2.echo `expr index "$string" is` # 输出 8
1.#!/bin/bash
2.
3.string="LCR is not loser"
4.
5.echo `expr index "$string" is`