扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

shell怎么查找字符串位置

扬州沐宇科技
2024-03-26 10:09:41
shell

在shell中查找字符串位置可以使用expr命令结合index函数来实现。以下是一个示例:

string="hello world"
substring="world"

position=$(expr index "$string" "$substring")
echo "Substring '$substring' found at position $position"

在这个示例中,string是要查找的字符串,substring是要查找的子字符串。expr index命令会返回子字符串在字符串中第一次出现的位置。

扫码添加客服微信