The thing to understand here is that 'and', 'or' and to some extent 'for'  
in fish are simple commands and fish doesn't track their usage in any  
particular way (like bash does). You have three choices:

1) Using begin/end to group expressions:
if begin test $i = "."; or test $i = ".."; end

2) Using and/or commandness:
test $i = "."; if or test $i = ".."


3) Using 'test' command syntax:
if test $i = "." -o test $i = ".."; end

regards,
Maxim

On Tue, 25 Aug 2015 08:12:14 +0300, 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?
>

------------------------------------------------------------------------------
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to