Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 610 Bytes

README.md

File metadata and controls

44 lines (34 loc) · 610 Bytes

ShellLearning

shell脚本学习(初学)

判断一个数是否为素数

#!/bin/bash

let isPrime=1

echo "input a number: "
read n

if [ ${n} -le 1 ]
then
  let isPrime=2
fi
for ((i=2;i<n;i++))
do
  let tmp=$(($n%$i))
  if [ $tmp -eq 0 ]
  then let isPrime=0
  break
  fi
done

# echo $isPrime

if [ $isPrime -eq 2 ]
then 
  echo "error!"
elif [ $isPrime -eq 1 ] 
then
  echo $n" is prime!"
else
  echo $n" is not prime!"
fi

用法

在Git中运行Git 下载