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
}
6
  • @123 What do you mean? Commented Dec 14, 2015 at 8:45
  • What's the problem/error you face? Commented Dec 14, 2015 at 8:47
  • @l3x I don't know how to calculate if I use it with -1 Commented Dec 14, 2015 at 8:51
  • What's this function supposed to do? Do you get any errors? Commented Dec 14, 2015 at 8:54
  • There's no echo for the m and h cases. Commented Dec 14, 2015 at 8:55

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

echo ${newtime}, That was my fault.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.