我想运行一个简单的bash计时器并在网上找到(用户brent7890)
#!/usr/bin/bash
timer=60
until [ "$timer" = 0 ]
do
clear
echo "$timer"
timer=`expr $timer - 1`
sleep 1
done
echo "-------Time to go home--------"
Run Code Online (Sandbox Code Playgroud)
我无法复制和粘贴此代码,因为服务器位于另一个网络上.我打字就像这样(下面)并在以"until"开头的行上出错.
#!/usr/bin/bash
timer=60
#Note I forgot the space between [ and "
until ["$timer" = 0 ]
do
clear
echo "$timer"
timer=`expr $timer - 1`
sleep 1
done
echo "-------Time to go home--------"
Run Code Online (Sandbox Code Playgroud)
这样的间距记录在哪里?这很重要.Bash脚本可能令人困惑,我想了解为什么空间很重要.
有几个规则,其中两个基本是:
[这是一个命令(test).
如果你写["$timer"这意味着你开始命令[60,那当然是不正确的.命令的名称是[.
命令的名称始终与命令行的其余部分隔开一个空格.(您可以在其中包含一个带空格的命令,但在这种情况下,您必须在""或中写入命令的名称'').