Cannot get grep to work within function.

Hello again,

Am having an issue now with getting a simple grep command to work within a function..

The function is as below...

function findRecord() {
                output=grep "001" recordDatabase
                echo $output
}                
 

At the moment the "001" is there to test the code, realistically it will be $1 and the findRecord function will be called from inside another function where it is passed the variable which sits in $1.

Hope that makes sense, let me know if i'm not being clear enough.

Thanks in advance.

try like this,

output=$(grep "001" recordDatabase)
1 Like

Code :

$cat test.fnc 
v1=$1
function findRecord() {
                output=`grep $v1 recordDatabase`
                echo $output
}
#call function
findRecord
execute the function 

$sh test.fnc  "red"
1 Like

thanks for the replies everyone :slight_smile: got it working now :slight_smile: