linux - 如何在Linux中搜索单词中的某些字母?

标签 linux bash shell

在 shell run.sh 中我有

find . -name "*.txt" -exec grep -H SNR {} \; | grep "$1" > result.txt
if[ "$1" -eq "offs0.5"] 
 then 
 fi

如果我输入:run.sh offs0.5

这个错误:

[: offs0.5 : integer expression expected

最佳答案

要进行字符串比较,您需要使用类似以下内容的内容:

[ "$1" == "offs0.5" ] 

请注意,在比较字符串时,使用 eq 的表达式正在寻找算术比较。

而且,在你的表情中,你有

if[ "$1" -eq "offs0.5"] 
          ^^^        ^ needed space
          no eq on string comparison

测试

$ d="offs0.5"
$ 
$ [ "$d" == "offs0.5" ] && echo "yes"
yes

$ d="offs0.5aa"
$ [ "$d" == "offs0.5" ] && echo "yes"

关于linux - 如何在Linux中搜索单词中的某些字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19403238/

相关文章:

linux - 如何在 bash 中在一行中运行多个后台命令?

linux - yum和rpm显示安装的包数不一样

ruby - 我可以从 Ruby 中的系统调用中获得连续输出吗?

macos - 在 Mac OS X 上仅在关机时运行脚本(不是注销或重新启动)

linux - 将进程的 STDOUT 发送到屏幕和第二个进程,但等待两者完成

linux - Apache httpd 请求/响应日志记录

bash - sed 到 grep 两个模式之间的字符串

linux - 我们可以在执行脚本后更改SHELL环境变量和解释器吗

bash - 使用 ls 和 grep 列出具有特定扩展名的文件

c - 关于 "int"flavors 操作的疑问