determine if csh variable is numeric

Christopher L Judd clj2289 at garnet.acns.fsu.edu
Thu Jul 14 18:35:41 UTC 2005


Thanks for the good suggestions.

On Thu, 14 Jul 2005, Will McDonald wrote:

> There's probably a more elegant way but you could echo it to grep and
> test the return value?
>
>
> [wmcdonald at willspc ~]$ set numval=13
> [wmcdonald at willspc ~]$ echo $numval
> 13
> [wmcdonald at willspc ~]$ echo $numval | egrep
> '[:alpha:]|[:cntrl:]|[:graph:]|[:punct:]'
> [wmcdonald at willspc ~]$ echo $?
> 1
> [wmcdonald at willspc ~]$ echo $shell
> /bin/tcsh
> [wmcdonald at willspc ~]$
>
> Wrap that in some shell logic and you should be sorted. I don't really
> do csh but in sh/ksh/bash you could do something like...
>
> if (echo $variable | egrep '[:alpha:]|[:cntrl:]|[:graph:]|[:punct:]')
> then
>    # variable's not numeric
>    echo "Variable $variable is NOT numeric"
> else
>   # It's numeric (or null, you'll need to test for that too)
>   echo "Variable $variable is numeric."
> fi
>
> Will.
>
> On 14/07/05, Christopher L Judd <clj2289 at garnet.acns.fsu.edu> wrote:
> > Would anyone know how to determine if a variable in the csh shell is
> > numeric or string?
> >
> > Thanks,
> > Chris
> >
> > --
> > redhat-list mailing list
> > unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> > https://www.redhat.com/mailman/listinfo/redhat-list
> >
>




More information about the redhat-list mailing list