2016-02-23 70 views
0

我有一个shell脚本,出现以下问题: 每次我再次执行脚本时,变量CURRENT都会重新设置为0,但是如何才能使CURRENT在每次之后都被保存脚本执行?将全局变量存储在shell脚本中

#!/bin/sh 
CURRENT=0 
A='Knight rider' 
B='Full color mood blobs' 
C='Police Lights Single' 
D='Police Lights Solid' 
E='Rainbow mood' 
F='Rainbow swirl' 
G='Rainbow swirl fast' 
H='Snake' 
I='Strobe blue' 

case $CURRENT in 
    0) hyperion-remote --effect "$A"; CURRENT=$(($CURRENT + 1));; 
    1) hyperion-remote --effect "$B"; CURRENT=$(($CURRENT + 1));; 
    2) hyperion-remote --effect "$C"; CURRENT=$(($CURRENT + 1));; 
    3) hyperion-remote --effect "$D"; CURRENT=$(($CURRENT + 1));; 
    4) hyperion-remote --effect "$E"; CURRENT=$(($CURRENT + 1));; 
    5) hyperion-remote --effect "$F"; CURRENT=$(($CURRENT + 1));; 
    6) hyperion-remote --effect "$G"; CURRENT=$(($CURRENT + 1));; 
    7) hyperion-remote --effect "$H"; CURRENT=$(($CURRENT + 1));; 
    8) hyperion-remote --effect "$I"; CURRENT=0;; 
esac 

回答

0

使用环境变量。

不要忘记在脚本末尾更新$ CURRENT。

相关问题