Q:

regex - to check if input is number in csh(unix)

Please help. How to make regex work in an if condition, 
to check user input(in 2nd parameter) must be not equal to any number? 
set regex="^[0-9]+$"
if ($#argv == 2 && $2 != $regex) then
# do this

A:

grep-based solution that only works for non-negative integers.
#!/bin/csh

# Note this requires 2 command line arguments, and checks the second one
# cshell arguments are 0-indexed.
if ($#argv == 2) then

    # Note the different grep regexp syntax, and you must use single quotes
    set test = `echo $2 | grep '^[0-9]*$'`
    if (($test) || ($test == 0)) then
        echo "Bad input"
    else
        echo "Ok!"
    endif
endif

