更新时间:2023-11-28 13:26:40
基于grep的解决方案仅适用于非负整数。
#!/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