Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Bash to Read File Then Do "grep" with The Line Against The File Itself

Tags:

linux

grep

bash

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?

like image 903
user2675805 Avatar asked Nov 12 '22 22:11

user2675805


1 Answers

Use grep -F (fixed string) instead:

var1=$(grep -F "$line" "$path")
like image 145
anubhava Avatar answered Nov 14 '22 23:11

anubhava