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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…