Can someone please explain why this doesn't work? I have a bash function that simply returns the number of seconds in a duration timestamp.
Shell script function
seconds() {
result=$(echo "\"1970-01-01 $1+0\"")
echo date +%s -d $result
}
Calling the function
seconds 00:00:02.00 #works
Produces the following output date +%s -d "1970-01-01 00:00:02.00+0"
if I copy this exact text and execute it in the terminal it works.
$(seconds 00:00:02.00) #error
However this returns an error:
date: extra operand ‘00:00:02.00+0"’
What's the problem here? Or is there a better way to do this?