Validation 如何在UNIX中验证参数是否为整数?

Validation 如何在UNIX中验证参数是否为整数?,validation,unix,integer,Validation,Unix,Integer,我正在编写一个脚本,其中第二个参数必须是整数,但我不知道如何检查参数是否为整数 if test $2 =~ "^[0-9]+$" then echo "\nNumero entero" else echo "\nError: El numero $2 no es un numero entero !!!\a" fi 差不多。我假设一个bash shell: #!/bin/bash result=$(echo "$2" | grep '^[0-9][0-9]*$') if [ -

我正在编写一个脚本,其中第二个参数必须是整数,但我不知道如何检查参数是否为整数

if test $2 =~ "^[0-9]+$"
 then
  echo "\nNumero  entero"
 else
  echo "\nError: El numero $2 no es un numero entero !!!\a"
 fi

差不多。我假设一个bash shell:

#!/bin/bash
result=$(echo "$2" | grep '^[0-9][0-9]*$')
if [ -n "$result" ]
then
    echo 'Integer!'
else
    echo "Error: '$2' is not an integer"
fi

D:它向我抛出了这个:grep:invalize选项--E用法:grep-hblcnsviw模式文件。这个呢?grep'^[0-9][0-9]*$'现在它可以工作了!谢谢你,伙计。。。嘿,但是你能告诉我我应该搜索什么主题来了解更多信息吗?你应该尝试了解你正在使用的shell。我假设bash是因为它是最常见的。例如:当然,还有命令“mangrep”或任何关于正则表达式的文本