Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix CSH-检查变量是否为整数_Unix_Scripting_Csh - Fatal编程技术网

Unix CSH-检查变量是否为整数

Unix CSH-检查变量是否为整数,unix,scripting,csh,Unix,Scripting,Csh,我已经试过了,但是即使我把一个数字设为$3,它仍然会出现在“notnumeric”语句中 if ($#argv == 3) then if ( $3 !~ '^[0-9]+$' ) then echo "Not numeric" exit 1 else echo "Numeric" endif endif 强制性的“不要使用csh”链接-和 也就是说,您的问题是您引用了regex模式。将其更改为此应该可以: if ( $3 !~ ^[0-

我已经试过了,但是即使我把一个数字设为$3,它仍然会出现在“notnumeric”语句中

if ($#argv == 3) then
   if ( $3 !~ '^[0-9]+$' ) then
      echo "Not numeric"
      exit 1
   else
      echo "Numeric"
   endif 
endif
强制性的“不要使用csh”链接-和

也就是说,您的问题是您引用了regex模式。将其更改为此应该可以:

if ( $3 !~ ^[0-9]+$ ) then

为了避免错误的数字格式,如果(“$3”!~“^[0-9]+$”)那么它应该是