I want to keep all files not ending with .bat
I tried
for f in $(ls | egrep -v .bat); do echo $f; done
and
for f in $(eval ls | egrep -v .bat); do echo $f; done
But both approaches yield the same result, as they print everything. Whereas ls | egrep -v .bat
and eval ls | egrep -v .bat
work per se, if used apart from the for
loop.
EDIT
It's interesting to see that if I leave out the -v
flag, the loop does what it should and lists all files ending with .bat
.
Feel free to edit the question title, as I was not sure what the problem is.
I'm using GNU bash, version 4.1.10(4)-release (i686-pc-cygwin).
EXAMPLE
$ ls -l | egrep -v ".bat"
total 60K
-rwx------+ 1 SYSTEM SYSTEM 5.3K Jun 6 20:31 fsc*
-rwx------+ 1 SYSTEM SYSTEM 5.3K Jun 6 20:31 scala*
-rwx------+ 1 SYSTEM SYSTEM 5.3K Jun 6 20:31 scalac*
-rwx------+ 1 SYSTEM SYSTEM 5.3K Jun 6 20:31 scaladoc*
-rwx------+ 1 SYSTEM SYSTEM 5.3K Jun 6 20:31 scalap*
Command is working, but not in the for loop.
$ for f in $(ls | egrep -v .bat); do echo $f; done
fsc
fsc.bat
scala
scala.bat
scalac
scalac.bat
scaladoc
scaladoc.bat
scalap
scalap.bat
scalac
scalac.bat
scaladoc
scaladoc.bat
scalap
scalap.bat
DEBUG $ set -x
mike@pc /cygdrive/c/Program Files (x86)/scala/bin
$ for f in $(ls | egrep -v .bat); do echo $f; done
++ ls -hF --color=tty
++ egrep --color=auto -v .bat
+ for f in '$(ls | egrep -v .bat)'
+ echo fsc
fsc
+ for f in '$(ls | egrep -v .bat)'
+ echo fsc.bat
fsc.bat
// and so on
ls
. – Mat Aug 26 '13 at 15:37for
loop. – Valentin Bajrami Aug 26 '13 at 15:45