aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-05-20 23:59:53 -0500
committerRob Landley <rob@landley.net>2015-05-20 23:59:53 -0500
commitadcbaf530f3ec351ec2932ebe9b77140f79eda4a (patch)
tree4dda98505a4f750b1b5c5da9ae703ec701a7171f
parent9720e4dbc9f65c1ebead58ea5e03c552a37e4113 (diff)
downloadtoybox-adcbaf530f3ec351ec2932ebe9b77140f79eda4a.tar.gz
Make "grep -r regex" work on implicit "." if no files specified.
-rw-r--r--toys/posix/grep.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 61df08ea..6e383efc 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -269,7 +269,7 @@ static int do_grep_r(struct dirtree *new)
void grep_main(void)
{
- char **ss;
+ char **ss = toys.optargs;
// Handle egrep and fgrep
if (*toys.which->name == 'e' || (toys.optflags & FLAG_w))
@@ -277,9 +277,9 @@ void grep_main(void)
if (*toys.which->name == 'f') toys.optflags |= FLAG_F;
if (!TT.e && !TT.f) {
- if (!*toys.optargs) error_exit("no REGEX");
+ if (!*ss) error_exit("no REGEX");
TT.e = xzalloc(sizeof(struct arg_list));
- TT.e->arg = *(toys.optargs++);
+ TT.e->arg = *(ss++);
toys.optc--;
}
@@ -294,7 +294,7 @@ void grep_main(void)
}
if (toys.optflags & FLAG_r) {
- for (ss=toys.optargs; *ss; ss++) {
+ for (ss = *ss ? ss : (char *[]){".", 0}; *ss; ss++) {
if (!strcmp(*ss, "-")) do_grep(0, *ss);
else dirtree_read(*ss, do_grep_r);
}