If you don't want (or with some other example, can't) use the `-a` and `-o` options of the `test` command, you use the result of chaining commands with the built-in `and` and `or` by wrapping the entire chain in a `begin; end` block:
```fish function xlist for i in (command ls -1a) if begin; test $i = "."; or test $i = ".."; end continue end echo $i end end ``` On Tue, Aug 25, 2015 at 1:12 AM Luciano ES <lucm...@gmail.com> wrote: > Yes, I googled and looked it up in the manual, and still can't solve this. > > Consider this script: > > #!/usr/bin/env fish > function xlist > for i in (command ls -1a) > echo $i > end > end > > I run it and get 194 items including files and directories. That is wrong. > It should be 192. Ah, sure, it's counting . and .. so it adds two. Let's > fix it: > > #!/usr/bin/env fish > function xlist > for i in (command ls -1a) > if test $i = "." > continue > end > if test $i = ".." > continue > end > echo $i > end > end > > Now I run it and get 192. Good! > > But what if I want the two conditions on one line? > > #!/usr/bin/env fish > function xlist > for i in (command ls -1a) > if test $i = "."; or test $i = ".." > continue > end > echo $i > end > end > > Now I get 193. The ".." entry (or rather the second conditional if I swap > . and .. in the script) is getting through the filter. > > What am I doing wrong? > > > As a side note, simple globbing (for i in *) returns the files only, not > any directories. Is that by design? > > > -- > Luciano ES > >> > > > ------------------------------------------------------------------------------ > _______________________________________________ > Fish-users mailing list > Fish-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/fish-users >
------------------------------------------------------------------------------
_______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users