Код: Выделить всё
if grep -wi $CODE codelist.txt = "true"
т.е. если поиск дал положительный результат то...
Как это правильно сделать?
Модераторы: /dev/random, Модераторы разделов
Код: Выделить всё
if grep -wi $CODE codelist.txt = "true"
Код: Выделить всё
if grep -q "cccc" *.txt; then echo "found"; fi
Это то же самое, что уже написано выше (с той разницей, что менее переносимо: ключ q, насколько я помню, есть только у GNU grep).drBatty писал(а): ↑26.05.2010 06:25наверное вы этого хотели?
Код: Выделить всё
if grep -q "cccc" *.txt; then echo "found"; fi
t.t писал(а): ↑26.05.2010 08:41Это то же самое, что уже написано выше (с той разницей, что менее переносимо: ключ q, насколько я помню, есть только у GNU grep).drBatty писал(а): ↑26.05.2010 06:25наверное вы этого хотели?
Код: Выделить всё
if grep -q "cccc" *.txt; then echo "found"; fi
Код: Выделить всё
GREP(1P) POSIX Programmer's Manual GREP(1P)
PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
NAME
grep - search a file for a pattern
SYNOPSIS
grep [-E| -F][-c| -l| -q][-insvx] -e pattern_list...
[-f pattern_file]...[file...]
grep [-E| -F][-c| -l| -q][-insvx][-e pattern_list]...
-f pattern_file...[file...]
grep [-E| -F][-c| -l| -q][-insvx] pattern_list[file...]
Да, ошибся. А что, неужели она и в стандарте есть?/dev/random писал(а): ↑26.05.2010 09:44Не только.t.t писал(а): ↑26.05.2010 08:41Это то же самое, что уже написано выше (с той разницей, что менее переносимо: ключ q, насколько я помню, есть только у GNU grep).drBatty писал(а): ↑26.05.2010 06:25наверное вы этого хотели?
Код: Выделить всё
if grep -q "cccc" *.txt; then echo "found"; fi
Код: Выделить всё
GREP(1P) POSIX Programmer's Manual GREP(1P) PROLOG This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME grep - search a file for a pattern SYNOPSIS grep [-E| -F][-c| -l| -q][-insvx] -e pattern_list... [-f pattern_file]...[file...] grep [-E| -F][-c| -l| -q][-insvx][-e pattern_list]... -f pattern_file...[file...] grep [-E| -F][-c| -l| -q][-insvx] pattern_list[file...]
Код: Выделить всё
$ /bin/grep -q
BusyBox v1.6.1 (2008-09-18 09:43:17 EEST) multi-call binary
Usage: grep [-HhrilLnqvsoeFEABC] PATTERN [FILEs...]
М-да.. Что-то я совсем устал... Некорректно вызвал команду для проверки -- это ж надо такое. Прошу прощения.