On 2014-04-27 20:26, Anton Aylward wrote:
On 04/27/2014 02:06 PM, Carlos E. R. wrote:
The intention here was for grep to locate the string "Bourne-Again" on the output text of the subshell. But it does not do that, it interprets it as the file(s) to look inside.
Of course it fails! Check the man page for grep. In that usage it take a list of files. What you subshell is producing is a texzt stream
I know that, and I said so in my email :-)
What you meant was
head -c 1000 bin/0_script_constructs | File - | Grep Bourne-Again
No need for an embedded subshell.
Ah... I see, yes. And if the exit code I get from that ( $? ) comes from the grep, it be fantastic. [...] Yep, it works: while read FILES ; do if [ -f "$FILES" ]; then TIPO=`head -c 1000 "$FILES" | file - | grep Bourne-Again` if [ $? -eq 0 ]; then echo "$FILES" >> $LISTADO_SCRIPTS fi fi done < $LISTADO_FIND Notes: a) The test for "regular file" is needed, because the find, despite using "find "$DONDE" -type f ..." finds some directories, and thus I get some errors later: head: error reading ‘/var/run/vmblock-fuse/dev’: Invalid argument head: error reading ‘/var/run/user’: Is a directory head: error reading ‘/var/run/systemd’: Is a directory head: error reading ‘/var/run/udev/links’: Is a directory head: error reading ‘/var/spool/news’: Is a directory head: error reading ‘/var/lib/ntp/proc’: Is a directory head: error reading ‘/proc’: Is a directory Some of those directories were supposedly excluded: find "$DONDE" -type f \ -prune -o -path '/var/spool/news' \ -prune -o -path '/var/run/udev/links' \ -prune -o -path '/var/run/user' \ -prune -o -path '/var/run/systemd' \ -prune -o -path '/var/lib/ntp/proc' \ -prune -o -path '/proc' \ -prune -o -path '/run/udev/links' \ > $LISTADO_FIND "/proc" should be avoided. The contents are avoided indeed, but not the parent. b) The use of: head -c 1000 "$FILES" | file - instead of directly: file "$FILES" is because "file" takes an awful amount CPU time to find out the types of all the files I feed it with, some of them huge (several gigabytes). To find out if it is a bash script needs only the first line of the script (the shebang), or a bit more if it is missing. -- Cheers / Saludos, Carlos E. R. (from 13.1 x86_64 "Bottle" at Telcontar)