Shell——之expr判断字符串与整数

说明:此脚本用于判断用户所输入的变量是否为整数


#!/bin/bash
while true
do
    read -p "Pls input:" a
    expr $a + 0 >/dev/null 2>&1
    [ $? -eq 0 ] && echo int || echo chars
done

测试结果:

 Shell——之expr判断字符串与整数