变量:类型只有数字、字符串、数组,不用分号
#!/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` #查找子字符串
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/280458.html