While POSIX 1003 compatibility is not a high priority for fish the `test`
command does follow the standard. You'll get a similar error in bash and
zsh. You should always quote the argument to `test -n` and `test -z`. Your
original code has other problems as well. For example, you assume that if
the first arg is `-s` that a second arg is present. Dangerous assumption.
Also, while many people prefer `test -z "$argv"` because that is what they
would do in bash the fishy way to do this is `not set -q argv[1]`

On Sat, Jun 24, 2017 at 2:48 PM, Greg Reagle <greg.rea...@umbc.edu> wrote:

> Hello.  I am using fish version 2.6.0.
>
> I wrote the following script: cat testing-test.fish:
> ---
> #!/usr/bin/fish
>
> test -z $argv; and echo NO argument
> ---
>
> greg@t400 ~/s/bin> ./testing-test.fish
> NO argument
> greg@t400 ~/s/bin> ./testing-test.fish 1
> greg@t400 ~/s/bin> ./testing-test.fish 1 2
> test: unexpected argument at index 2: '2'
> greg@t400 ~/s/bin> ./testing-test.fish 1 2 3
> test: Expected a combining operator like '-a' at index 2
> g
>
> No surprises when called with no command line arguments or with "1", but
> after that it goes off the rails.  Am I doing it wrong?  If so, what is
> the proper fishy way to test for the existence of command line
> arguments?
>
> Note that I discovered this problem in a larger more sophisticated
> script, but I have simplified and condensed it.  The excerpt from my
> actual script is:
> ---
> if test -z $argv;            set delay 300
> else if test $argv[1] = -s;  set delay $argv[2]
> else;                        set delay (expr $argv[1] '*' 60)
> end
> ---
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Fish-users mailing list
> Fish-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/fish-users
>



-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to