Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am working on a project on two different machines - one running Mac OSX 10.8.3, and one running Red Hat Enterprise Linux. On my Mac, I can do this:

vim $(ls -R */*.@(h|cpp) */*/*.@(h|cpp))

and everything works fine. On the Linux box, it fails. All of these work exactly as I expect:

ls -R */*.@(h|cpp) */*/*.@(h|cpp)
echo $(ls -R */*.@(h|cpp) */*/*.@(h|cpp))
export myfilelist=$(ls -R */*.@(h|cpp) */*/*.@(h|cpp))
echo $myfilelist

But

vim $(ls -R */*.@(h|cpp) */*/*.@(h|cpp))

produces a set of mangled filenames, e.g.

^[[00m^[[00mevent_builder/include/eb_service.h^[[00m" [New DIRECTORY]

or

:ls
  1 %a   "^[[00m^[[00mevent_builder/include/eb_service.h^[[00m" line 1
  2      "^[[00mevent_builder/include/EventBuilder.h^[[00m" line 0

Does anyone know why?

share|improve this question
    
As Glenn points out, the [[00m stuff is ansi sequences used to color output on an ansi compatible terminal. ls --color=never may help, see the man page. –  TAFKA 'goldilocks' Mar 21 '13 at 13:42
add comment

1 Answer

up vote 9 down vote accepted

You have an alias (or function) for ls that colorizes the output. What does type -a ls give you? Instead use

vim $(command ls ...)

However: don't parse ls

Try

shopt -s nullglob globstar
printf "%s\n" **/*.{h,cpp}
share|improve this answer
    
Ah, of course, colors. Great answer, thank you! (For the record, on my Mac, type -a ls = ls is aliased to ls -Fh', and on the Linux box it is = ls is aliased to ls -F --color') –  Gabriel Perdue Mar 21 '13 at 13:52
1  
@GabrielPerdue Fix your alias: make it alias ls='ls -F --color=auto'. –  Gilles Mar 21 '13 at 23:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.