我试图在bash中比较字符串。我已经在stackoverflow上找到了如何做到这一点的答案。在脚本中,我正在尝试,我正在使用Adam在提到的问题中提交的代码:
#!/bin/bash
string='My string';
if [[ "$string" == *My* ]]
then
echo "It's there!";
fi
needle='y s'
if [[ "$string" == *"$needle"* ]]; then
echo "haystack '$string' contains needle '$needle'"
fi
我也尝试了ubuntu论坛的方法,你可以在第二篇文章中找到
if [[ $var =~ regexp ]]; then
#do something
fi
在这两种情况下,我收到错误:
[[: not found
我做错了什么?