grep is always recursive
Matthew Flaschen
matthew.flaschen at gatech.edu
Thu Jan 29 23:21:06 UTC 2009
Lorenzo Luengo wrote:
> I think it's also a great idea. And it does not break backwards
> compatibility! Let's see our study case:
>
> $ ls
> somefile -r somotherfile
>
> Now when you do
> $ grep someword *
>
> It would expand to
> $ grep someword somefile ./-r somotherfile
>
> and everything should work as everyone intended.
It's not backwards-compatible. Below is a sample script that breaks.
Granted, it's slightly contrived, but nonetheless a valid example. To
test it, save as author_from_initials.sh, then do:
chmod a+x author_from_initials.sh
mkdir author_test
touch author_test/JES_proposal.txt
cd author_test
../author_from_initials.sh *
It will print:
JES_proposal.txt: John Edwards Smith
If you do:
../author_from_initials.sh ./JES_proposal.txt
(the latter is what your proposal entails), it will give:
./JES_proposal.txt: Author not found
Matthew Flaschen
--------------------------------------------------
#!/bin/sh
for filename in "$@"
do
echo -n "$filename: "
case $filename in
JES*)
echo "John Edwards Smith"
;;
MJT*)
echo "Mary Jane Thompson"
;;
*)
echo "Author not found";
;;
esac
done
More information about the ubuntu-users
mailing list