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


#!/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判断字符串与整数

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
  • 2021-12-10
  • 2021-12-03
  • 2021-05-31
  • 2022-12-23
猜你喜欢
  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-12-04
  • 2022-01-22
  • 2021-09-03
相关资源
相似解决方案