我正在编写一个脚本,以便在脚本运行后将数据添加到文件中。 由于我需要转发邮件数据,因此我需要一个变量来分配调用脚本的次数。
我正在使用一个存储计数值的临时文件。每次调用脚本时,都会调用变量 temp,该值会递增并存储在 count 中。增加的值然后存储回温度。
count=$((temp + 1))
echo $count > temp
printf "%d\t%10s\t" "$count" "$datet" >> table
这是我正在使用的代码,但温度没有增加......?
最佳答案
在执行其他操作之前先读取之前的值:
temp=$(cat temp)
count=$((temp + 1))
echo "$count" > temp
printf "%d\t%10s\t" "$count" "$datet" >> table
测试
$ echo "0" > temp
$ ./a
$ cat temp
1
$ ./a
$ cat temp
2
关于shell - 如何添加一个变量来计算脚本被调用的次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24302210/