shell 变量 使用删除 获取字符串长度

1.使用变量
your_name="qinjx"
echo $your_name
echo ${your_name}

2.只读变量
myUrl="https://www.google.com"
readonly myUrl
myUrl="https://www.runoob.com"

3.删除变量 变量被删除后不能再次使用。unset 命令不能删除只读变量。
unset variable_name

4拼接字符串
your_name="runoob"
greeting_1="hello, ${your_name} !"
# 使用单引号拼接
greeting_3='hello, ${your_name} !'

5.获取字符串长度
string="abcd"
echo ${#string} #输出 4

6.提取子字符串
string="runoob is a great site"
echo ${string:1:4} # 输出 unoo

posted @ 2021-02-18 15:08  简单音乐  阅读(98)  评论(0)    收藏  举报