【发布时间】:2017-04-10 12:47:36
【问题描述】:
这就是我想要做的:
我想制作一个脚本,我可以使用counter_use in 或counter_use out 调用它。如果我输入in,我想要一个计数器为名为“counter”的文件中的数值加1,如果我输入out,我想从文件中减去1。
如果计数器中的值等于或大于 1,我还希望脚本输出 Logged in,如果计数器等于 0,则输出 Not logged in。
如果我将计数器硬编码为特定数字,则最后一部分将运行。问题是第一部分。
echo "In or out?"
read input > counterFile
if grep -q "in" counterFile
then //what should I do here so that it adds +1 to a file called
counter?
elif grep -q "out" counterFile
then //what should I do here so that it subtracts -1 to a file called
counter?
if [ $counter -ge 1 ]
then
echo "Logged in"
elif [ $counter -eq 0 ]
then
echo "Not logged in"
else
echo "Wrong input"
fi
【问题讨论】: