On Tue, 5 Mar 2019, Tassilo Horn wrote: > 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?
$argv[2] is empty, which means the second part of the expression expands to "( -z )". Try: \( -z "$argv[2]" \) > 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. You might like to open an issue on GitHub to discuss this change. The behaviour is similar between bash/zsh using `[` (rather than `[[`) and fish. David Adam zanc...@ucc.gu.uwa.edu.au _______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users