Shell编程
作者:互联网
变量:类型只有数字、字符串、数组,不用分号
#!/bin/sh
str_name="jack" #变量赋值,等号俩边不能有空格,比如str_name = "jack"、str_name= "jack"
echo $str_name
echo ${str_name}
readonly str_name #定义只读,不带$
unset str_name #删除变量,不带$
str_say = "hello, ${str_name} !" #拼接字符串
str_say = "hello", ${str_name} ! #拼接字符串
str_say = hello, ${str_name} ! #拼接字符串
len = ${#str_say} #获取字符串长度
len = ${#str_say[0]} #获取字符串长度,一样效果
str_sub = ${str_name:1:3} #字符串截取:${字符串:开始位置:截取长度},第一个字符的索引值为 0
echo `expr index "$string" io` #查找子字符串
标签:Shell,name,编程,say,jack,str,字符串,hello 来源: https://www.cnblogs.com/feiying100/p/16584748.html