This commit is contained in:
flykhan 2023-08-14 17:48:45 +08:00
parent cdd2f13b5b
commit 52ae50ce5e
8 changed files with 106 additions and 0 deletions

26
day1/d22.sh Normal file
View File

@ -0,0 +1,26 @@
#!/bin/bash
echo "please input y/n"
read yn
case $yn in
# | 表示或的意思
y|Y|yes|Yes|YES)
echo "your input yes ..."
;;
n)
echo "your input no ..."
;;
*)
echo "your input is invalid argument"
exit 1
esac
# if [ "$yn" = "y" ]; then
# echo "your input yes ..."
# elif [ "$yn" = "n" ]
# then
# echo "your input no ..."
# else
# echo "your input is invalid argument"
# fi

12
day1/d23.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# declare 是 Bash 内置命令,用于声明变量的属性,包括类型、作用域和初始值等。
declare -i total=0
for (( i=5;i<=100;i++ )); do
if (( i%5 == 0 )); then
total+=i
fi
done
echo "$total"

14
day1/d24.sh Normal file
View File

@ -0,0 +1,14 @@
#!/bin/bash
declare -i n
read -p "请输入一个整数: " n
for (( i=2; i<n; i++ )); do
if (( n%i == 0)); then
echo "$n 不是素数"
exit 1
fi
done
echo "$n 是素数"
echo "$n"

10
day1/d25.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
declare -i total=0
for line in `ls *.sh`
do
total+=`ls -l $line | awk '{print $5}'`
done
echo "所有 sh 文件的总大小为: $total 字节"

8
day1/d26.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
echo "请输入内容exit退出: "
read -p ">" cmd
while [ $cmd != "exit" ]; do
echo "$cmd"
read -p ">" cmd
done

8
day1/d27.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/bash
echo "请输入内容exit退出: "
read -p ">" cmd
until [ $cmd == "exit" ]; do
echo "$cmd"
read -p ">" cmd
done

10
day1/d28.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
declare -i ret=1
declare -i n
read -p "整数: " n
until [ $n -eq 1 ]; do
ret=ret*n
n=n-1
done
echo "$ret"

18
day1/d29.sh Normal file
View File

@ -0,0 +1,18 @@
#!/bin/bash
function isZs()
{
declare -i n
n=$1
for(( i=2; i<n; i++ )); do
if (( n%i == 0 )); then
return 1
fi
done
return 0
}
isZs $1
if [[ $? -eq 0 ]] ; then
echo "$1 是素数"
fi