tags:

views:

50

answers:

4

what is wrong with this?

for i in 'ls | grep '^[A-Z]......$' do echo $i done

if i just use the command ls | grep '^[A-Z]......$ i get the files i want

What am i missing?

M

+1  A: 

you mean

for i in `ls | grep '^[A-Z]......$'`;do echo $i;done

? actully this is difference between ` and ' , limited within your shell, and not a regex or OS problem.

jokester
+1 instead of backticks you can also use `$(....)` for command substitution. See http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html
rudi-moore
i still can't get this to work?
matt123
there is no need to use external commands. see my answer
ghostdog74
A: 

Shouldn't those be backticks?

 for i in `ls | grep blahblahblah`; do echo $i; done
Borealid
+1  A: 

When you use the backtick: "`" instead of the single quote "'" the output of the program between the backticks will be used as input for the shell, i.e.

for i in `ls | grep '^[A-Z]......$'`;do echo $i;done
Marc van Kempen
+3  A: 

the thing that is "wrong" , is that there is no need to use external ls command to list your files and grep your pattern. Just use the shell.

for file in [A-Z]??????
do
 echo $file
done
ghostdog74