Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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]


  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. – goldilocks Mar 21 '13 at 13:42
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


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
@GabrielPerdue Fix your alias: make it alias ls='ls -F --color=auto'. – Gilles Mar 21 '13 at 23:03

Your Answer


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.