Syntax error: invalid loop variable

I am trying to write a script that will play the radio in the background

#!/bin/sh

for (( i = 80 ; i <= 101; i++ )) 
 do 
  amixer cset numid=1 i$% sleep 60;
done 

      

But I have a problem:

alarmclock-vol.sh: 3: alarmclock-vol.sh: Syntax error: Bad for loop variable

      

+3


source to share


1 answer


Syntax is for (( expr ; expr ; expr ))

not available in sh

. Switch to bash or ksh93 if you want to use this syntax. Otherwise, the equivalent for sh is:



#!/bin/sh

i=80
while [ "$i" -le 101 ]; do
    amixer cset numid=1 "$i%"
    sleep 60
    i=$(( i + 1 ))
done 

      

+7


source







All Articles