Name: Anonymous 2012-02-27 13:29
How do I grep a given path and not the contents of the file in bash? ls won't work because the path is actually an input file, $1. Thanks.
{
if echo $1 | grep "lol" ; then
echo "fucking echo the filename then pipe it to your mom."
fi
}
find . | grep wabbles
x/y/z/wabbles/wek.tt
wabbels.tt
r/wabbels/y.tt
find . -name \*RTFM\*
if ($path =~ /lol/) {
say "This pathname is HILARIOUS";
}
$ WABS=hello
$ if echo $WABS | grep hell > /dev/null; then echo "haha it contained hell!"; else echo "it did not contain hell"; fi
haha it contained hell!
$ WABS=welcome
$ if echo $WABS | grep hell > /dev/null; then echo "haha it contained hell!"; else echo "it did not contain hell"; fi
it did not contain hell
-q or --quiet option for this purpose. Besides, if you have to redirect stdout, you should redirect stderr, too.^ and $ to mark the beginning and end of the line, and use the dirname and basename commands to grab the parent directory and the filename, respectively (echo `basename $1` | grep -q lol).