标签:用户 shell脚本 normal 开头 使用 返回 app 第一个 exp
比较是否相等 =
|
运算符
|
含义( 满足下面要求时返回 TRUE ) |
|
-e file
|
文件 file 已经存在 |
|
-f file
|
文件 file 是普通文件 |
|
-s file
|
文件 file 大小不为零 |
|
-d file
|
文件 file 是一个目录 |
|
-r file
|
文件 file 对当前用户可以读取 |
|
-w file
|
文件 file 对当前用户可以写入 |
|
-x file
|
文件 file 对当前用户可以执行 |
|
-g file
|
文件 file 的 GID 标志被设置 |
|
-u file
|
文件 file 的 UID 标志被设置 |
|
-O file
|
文件 file 是属于当前用户的 |
|
-G file
|
文件 file 的组 ID 和当前用户相同 |
|
file1 -nt file2
|
文件 file1 比 file2 更新 |
|
file1 -ot file2
|
文件 file1 比 file2 更老 |
|
1
2
3
4
5
6
|
str="apple, tree, apple tree"echo ${str/apple/APPLE} # 替换第一次出现的appleecho ${str//apple/APPLE} # 替换所有appleecho ${str/#apple/APPLE} # 如果字符串str以apple开头,则用APPLE替换它echo ${str/%apple/APPLE} # 如果字符串str以apple结尾,则用APPLE替换它 |
[[ "a.txt" == a* ]] # 逻辑真 (pattern matching)[[ "a.txt" =~ .*\.txt ]] # 逻辑真 (regex matching)[[ "abc" == "abc" ]] # 逻辑真 (string comparision)[[ "11" < "2" ]] # 逻辑真 (string comparision), 按ascii值比较取长度
str="abcd"expr length $str # 4echo ${#str} # 4expr "$str" : ".*" # 4好像一般使用第二种
查找子串的位置
str="abc"expr index $str "a" # 1expr index $str "b" # 2expr index $str "x" # 0expr index $str "" # 0
选取子串
"abcdef"expr substr "$str" 1 3 # 从第一个位置开始取3个字符, abcexpr substr "$str" 2 5 # 从第二个位置开始取5个字符, bcdefexpr substr "$str" 4 5 # 从第四个位置开始取5个字符, defecho ${str:2} # 从第二个位置开始提取字符串, bcdefecho ${str:2:3} # 从第二个位置开始提取3个字符, bcd
标签:用户 shell脚本 normal 开头 使用 返回 app 第一个 exp
原文地址:https://www.cnblogs.com/realplay/p/9648753.html