简体   繁体   English

使用Bash读取文件然后用“反对文件本身”行“grep”

[英]Use Bash to Read File Then Do “grep” with The Line Against The File Itself

I am trying to read a file using Linux Bash and then use "grep" to run that line against the file itself. 我正在尝试使用Linux Bash读取文件,然后使用“grep”对文件本身运行该行。 It seems not working to me... 这似乎对我不起作用......

#!/bin/bash

path=$1
while read line
do
    var1=$(grep $line $path)
    echo $?
    exit
done < $path

The $? $? returns 1. What's going on here? 返回1.这里发生了什么?

使用grep -F (固定字符串)代替:

var1=$(grep -F "$line" "$path")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM