gpt4 book ai didi

bash - 如何在 bash shell 脚本变量中查找子字符串

转载 作者:行者123 更新时间:2023-11-29 08:50:50 25 4
gpt4 key购买 nike

我有一个如下所示的变量。

variable = This script is not found

if [[ "$variable" = ~ "not found" ]];
then
echo "Not Found"
else
echo "Its there"
if

在执行 im 时低于错误,

line 4: syntax error in conditional expression
./test.sh: line 4: syntax error near `found"'
./test.sh: line 4: `if [[ "$variable" = ~ "not found" ]]; '

谁能指出我,我在这里缺少什么?

最佳答案

LIST="some string with a substring you want to match"
SOURCE="substring"

if echo "$LIST" | grep -q "$SOURCE"; then
echo "matched";
else
echo "no match";
fi

祝你好运;)

关于bash - 如何在 bash shell 脚本变量中查找子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15118934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com