0

I would like to get the time from a config file and the multiply it. When I write the time like 30m it takes case m and uses 30m. But how I can I do calculations with this value.The case s is working as it should.

 getTimeFromConfig(){
case $timestart in
*s )
echo ${timestart::-1};;
*m )
time = ${timestart::-1}
newtime= $(($time*60));;
*h )
time = ${timestart::-1}
newtime= $(($time*3600));;
esac
}
aha364636
  • 365
  • 5
  • 23

1 Answers1

1

There shouldn't be any whitespace around = (assignment).

time = ${timestart::-1}
newtime= $(($time*60));;

should be

time=${timestart::-1}
newtime=$(($time*60));;

Similarly,

time = ${timestart::-1}
newtime= $(($zeit*3600));;

should be

time=${timestart::-1}
newtime=$(($zeit*3600));;

If you simply want to print the calculated value then do:

    echo ${newtime}

in each of the case statements of m and h.


If you want this function to "return" the time, you can either use a global variable or print from the function and read it from the caller:

At the end of getTimeFromConfig() do:

    echo ${newtime}
  }

and at the caller:

timevalue=$(getTimeFromConfig)
P.P
  • 117,907
  • 20
  • 175
  • 238