0

Hello I have an error in this code. I want to check if file is readable and writable and check if this file contains the string "/usr/bin/python2", but the shell prints this error:

grep /usr/bin/python2

How can I solve this?

if test -f $i -a test -w $i -a `grep /usr/bin/python2 < $i`
then
   echo $i
fi
2
if test -r "$i" -a -w "$i" && grep -q "/usr/bin/python2" "$i"
then
   echo "$i"
fi

You could also avoid the whole if statement and check for readability is done by grep implicitly:

test -w "$i" && grep -l "/usr/bin/python2" "$i" 2>/dev/null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.