First, if the error message is "should be in an empty directory", then why
is a empty 2nd argument part of that test? That should probably be a
separate test and separate error message.

I would test for empty directory like:

set files * .*
if test (count $files) != 0; echo error; end


And to test for empty parameters, use `set -q`

if not set -q argv[2]; echo "argv[2] is empty"; end



On Tue, Mar 5, 2019 at 8:59 AM Tassilo Horn <t...@gnu.org> wrote:

> Hi all,
>
> in a script, I have this code:
>
> --8<---------------cut here---------------start------------->8---
> if test \( (count (ls -A .)) != "0" \) -a \( -z $argv[2] \)
>     echo "This should be run in an empty directory."
>     exit 3
> end
> --8<---------------cut here---------------end--------------->8---
>
> It errors with:
>
>   test: Expected a combining operator like '-a' at index 4
>
> I don't see what's wrong here.  Do you?
>
> Of course, feel free to suggest a better way to encode that this script
> must be run in an empty directory unless there are at least two
> arguments given.
>
> And also I find it strange that the script runs although I get the
> (syntax?) error above.  With both Bash and ZSH, syntactical nonsense
> like
>
>   if [[ -a -z 1/1 ]]; then echo Yes; fi; echo Running
>
> does not print Running and returns exit code 2 whereas fish's equivalent
>
>   if test -a -z !; echo Yes; end; echo Running
>
> prints Running and returns zero.  In this case, I think the Bash/ZSH
> behavior is much better.  A syntax error should not be treated as simply
> a false expression.
>
> I'm running fish 3.0.1.
>
> Thanks,
> Tassilo
>
>
>
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fish-users
>


-- 
*Glenn Jackman*
Senior Software Developer

*Pythian - Love your data*
jack...@pythian.com
Tel: +1 613 565 8696 Ext. 1478
Mobile: +1 613 808 4984
www.pythian.com

-- 


--





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

Reply via email to