0

I'm doing some experimenting with fish, and I tried looping over the subdirectories of the current directory, something I do often in bash. fish's syntax is similar, and it was easy to just echo each directory name to make sure I had it correct.

for i in $(ls -d ./*); echo $i; end

Trying to do anything with the directory, however, yielded all sorts of errors. It took too long, but I finally discovered that fish installs an ls.fish function BY DEFAULT(!), that that function automatically uses colors, and that those colors were being passed by the loop to whatever command is being called.

Thus, for i in $(ls -d ./*); ls $i; end generated an error for each directory, because the ls in the subcommand used colors, which were included in $i, and the ls outside the subcommand choked on getting the color escape characters.

There are so many things wrong with all of that that it's hard to know where to begin, but for now I just have this question.

What is the "fish" way to bypass loading one or all of the functions that are installed with fish? (I've read the documentation, and done some web searching, and have found nothing.)

0

1 Answer 1

0

I think the lesson here is Don't parse ls

for item in *
  do_something_with $item
end

ref: Wildcards (“Globbing”)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .