I want to search a number of files "in a bash loop".
Suppose I exec an ack search in a bash loop:
#!/bin/bash
seq 3 | while read i
do
test=`ack root /etc/passwd`
echo $test
done
prints one empty line.
Where as
#!/bin/bash
seq 3 | while read i
do
# test=`ack root /etc/passwd`
echo $test
done
prints 3 empty lines.
If I ran just that one command from the bash it works:
ack root /etc/passwd
This also works:
$ test=`ack root /etc/passwd`
$ echo $test
I think ack somehow breaks the loop.
Here's "the origin of the problem":
ls input/* | while read scan
do
temp=`basename "$scan"`
baseName=${temp%.*}
extension=${temp#*.}
# OCR:
abbyyocr11 -rl Russian -if "$scan" -f TextUnicodeDefaults -of "temp/$baseName.txt"
# get data:
firstName=` ack '^Имя\s+(.+)' --output='$1' "temp/$baseName.txt" | sed 's/ //g'`
middleName=`ack '^Отчество\s+(.+)' --output='$1' "temp/$baseName.txt" | sed 's/ //g'`
lastName=` ack '^Фамилия\s+(.+)' --output='$1' "temp/$baseName.txt" | sed 's/ //g'`
# copy the file with a meaningful name:
cp --backup=numbered "$scan" "output/$lastName$firstName$middleName.$extension"
done
Edit
Turns out --nofilter
option solves it. According to --help
message it forces ack treat stdin as tty as opposed to pipe. I wonder what this means.