Today I had a pretty similar problem, and I came up with this code (including health checks):
#!/bin/sh # sanity checks if [ $# -lt 2 ]; then echo "USAGE : $0 PATTERN1 [[PATTERN2] [...]]"; echo "EXAMPLE: $0 TODO FIXME"; exit 1; fi NEEDLE=$(echo $* | sed -s "s/ /\\\|/g") grep $NEEDLE . -r --color=auto
This small script allows you to search for recursive words in all files below the current directory. You can use sed to replace your separator "(space) with whatever you like. I replace the space with a shielded tube:" "->" \ | "The resulting string can be analyzed by grep.
Using
Find the terms "TODO" and "FIXME":
./script.sh TODO FIXME
You may wonder: why not just call grep directly?
grep "TODO\|FIXME" . -r
The answer is that I wanted to do some post processing with the results in a more advanced script. Therefore, I needed to compress all the transferred arguments (templates) into one line. And here is the key part here.
Konrad
Konrad Kleine
source share