泰山神 发表于 2018-8-23 11:37:10

shell中的计算

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


页: [1]
查看完整版本: shell中的计算