Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: expansion in conditional expression patterns



Peter Stephenson wrote:
> Sebastian Stark wrote:
> > I just did this:
> > 
> >    if [[ ! ( ($cmdnum -ge 1) && ($cmdnum -le $limit) ) ]]
> > 
> > Maybe I should have asked differently because there might be a better  
> > solution for what I'm trying to do. I have an array of commands,  
> > $cmds, and a user supplied $cmdnum. Now I want to check wether the  
> > user entered a valid number. ($limit would be $#cmds in this example).
> > 
> > Is there a better way to check wether the user entered a) a number and  
> > b) in the range 1..$#cmds?
> 
> I don't think there's anything magic that you're missing.  I'd do
> something like:
> 
>   if [[ $cmdnum != <-> || $cmdnum -gt $#cmds ]]; then
>     # error
>   fi

... except it could be zero, so

if [[ $cmdnum != <1-> || $cmdnum -gt $#cmds ]]; then
    # error
fi

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



Messages sorted by: Reverse Date, Date, Thread, Author