user2675805
user2675805

Reputation: 181

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. 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?

Upvotes: 5

Views: 2832

Answers (1)

anubhava
anubhava

Reputation: 785128

Use grep -F (fixed string) instead:

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

Upvotes: 1

Related Questions