From 52ae50ce5eb08917b31af9e6dc7a320f7fe9b743 Mon Sep 17 00:00:00 2001 From: flykhan Date: Mon, 14 Aug 2023 17:48:45 +0800 Subject: [PATCH] shell --- day1/d22.sh | 26 ++++++++++++++++++++++++++ day1/d23.sh | 12 ++++++++++++ day1/d24.sh | 14 ++++++++++++++ day1/d25.sh | 10 ++++++++++ day1/d26.sh | 8 ++++++++ day1/d27.sh | 8 ++++++++ day1/d28.sh | 10 ++++++++++ day1/d29.sh | 18 ++++++++++++++++++ 8 files changed, 106 insertions(+) create mode 100644 day1/d22.sh create mode 100644 day1/d23.sh create mode 100644 day1/d24.sh create mode 100644 day1/d25.sh create mode 100644 day1/d26.sh create mode 100644 day1/d27.sh create mode 100644 day1/d28.sh create mode 100644 day1/d29.sh diff --git a/day1/d22.sh b/day1/d22.sh new file mode 100644 index 0000000..9b51f6d --- /dev/null +++ b/day1/d22.sh @@ -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 \ No newline at end of file diff --git a/day1/d23.sh b/day1/d23.sh new file mode 100644 index 0000000..296604b --- /dev/null +++ b/day1/d23.sh @@ -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" \ No newline at end of file diff --git a/day1/d24.sh b/day1/d24.sh new file mode 100644 index 0000000..e091f33 --- /dev/null +++ b/day1/d24.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +declare -i n +read -p "请输入一个整数: " n + +for (( i=2; i" cmd +while [ $cmd != "exit" ]; do + echo "$cmd" + read -p ">" cmd +done \ No newline at end of file diff --git a/day1/d27.sh b/day1/d27.sh new file mode 100644 index 0000000..8e1c106 --- /dev/null +++ b/day1/d27.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "请输入内容,exit退出: " +read -p ">" cmd +until [ $cmd == "exit" ]; do + echo "$cmd" + read -p ">" cmd +done \ No newline at end of file diff --git a/day1/d28.sh b/day1/d28.sh new file mode 100644 index 0000000..fe22b46 --- /dev/null +++ b/day1/d28.sh @@ -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" diff --git a/day1/d29.sh b/day1/d29.sh new file mode 100644 index 0000000..577e694 --- /dev/null +++ b/day1/d29.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +function isZs() +{ + declare -i n + n=$1 + for(( i=2; i