Calculate day number from date function fg: no job control

I have a function to calculate the number of days based on three parameters d, m, y

this is a function

function getDate (){
    d=$1
    m=$2
    y=$3
    m=$((m+9)) % 12
    y=$((y - m/10))
    return $((365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 )))
}

      

Call for example:

getDate 01 01 2015

      

The problem is that I always get line 8: fg: no job control

which is this linem=$((m+9)) % 12

+3


source to share


1 answer


Replace

m=$((m+9)) % 12

      

by

m=$(((m+9)%12))

      



Use $((expression))

for calculations.


return

can only return values ​​between 0 and 255. In your case, I suggest replacing return

with echo

.

+4


source







All Articles