Shiv
Shiv

Reputation: 1

find with grep not working inside shell script

I am using the below command to find the file names and it works fine when execute from command line:

$AIX->: find . | xargs grep -l "BE00036"
./6281723219129
$AIX->:

But the same command is not working when execute from shell script(ksh):

$AIX->: ksh test.ksh
**find: bad option -l**

part of my code is:

Var="find . | xargs grep -l \"BE00036\"
print `$Var`

Upvotes: 0

Views: 1852

Answers (2)

Vijay
Vijay

Reputation: 67221

This below one works for me:

var=`find . | xargs grep -l 'BE00036'`
echo "$var"

Upvotes: 0

pfnuesel
pfnuesel

Reputation: 15320

If you want to assign the output of a command to a variable, you can do

Var="$(find . | xargs grep -l \"BE00036\")"
print "$Var"

Upvotes: 2

Related Questions