[英]Bash script basic apnea timer
I am trying to write a bash script that will prompt a user for three variables, and then display a count down type timer so I can perform O2
tables whilst at work on my linux machine (centos6)
,我正在尝试编写一个 bash 脚本,它将提示用户输入三个变量,然后显示一个倒计时类型的计时器,这样我就可以在我的 linux 机器
(centos6)
上工作时执行O2
表,
So far I have a really bad mix of a loop and countdown function written but i am sure that this is a very basic script for someone who comprehends bash scripting,到目前为止,我编写的循环和倒计时 function 的组合非常糟糕,但我确信对于理解 bash 脚本的人来说,这是一个非常基本的脚本,
Essentially I need a variable for a time interval for a breath up (breathing deeply to prepare for a period of apnea) A variable for the first interval of time to hold your breathe Then a variable to increment that hold time by a user provided value as rounds go by,本质上,我需要一个用于呼吸的时间间隔的变量(深呼吸以准备一段时间的呼吸暂停)一个用于第一个时间间隔的变量以保持呼吸然后一个变量通过用户提供的值增加该保持时间为将 go 舍入,
I would prefer all the variable to be established in seconds only,我希望所有变量只在几秒钟内建立,
Here's an example able of what the end result should be:这是一个能够说明最终结果的示例:
this is what i had until i got frustrated with the operation of it这就是我所拥有的,直到我对它的操作感到沮丧
#!/bin/bash
echo "Welcome to the apnea timer, All values should be entered in seconds"
sleep 0.2
read -p "Enter Breath Up Time:" br
read -p "Enter Starting Hold Time Interval:" hold
read -p "Enter Hold Increment Time:" hinc
echo "Starting..."
sleep 0.5
function cw(){
date1=$((`date +%s` + $1));
while [ "$date1" -ne `date +%s` ]; do
echo -ne "$(date -u --date @$(($date1 - `date +%s`)) +%H:%M:%S)\r";
sleep 0.1
done
if [$br -gt 0]
do
cw $br
then
cw $hold
then
cw $br
then
cw ($hold + $hinc)
Maybe you got frustrated too soon.也许你过早地感到沮丧。 The hardest part, the countdown function
cw
, works - you just forgot the closing }
after the done
line -, only what follows is faulty.最难的部分,倒计时 function
cw
,工作 - 你只是忘记了done
线之后的关闭}
-,只有下面的内容是错误的。 So after the done
you could write:所以
done
后你可以写:
}
for set in `seq 8`
do echo Set $set
echo Breath
cw $br
echo
echo Apnea
cw $hold
echo
let hold+=hinc
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.