There are several syntax and a quite obvious logic one (return 0)
A working version is below:
#!/bin/bash
factorial()
{
if (( $1 <= 1 )); then
echo 1
else
last=$(factorial $(( $1 - 1 )))
echo $(( $1 * last ))
fi
}
factorial 5
You are missing:
-
return is bad (should use
echo) -
shbang line (is /bin/bash not /bash/bin)
-
Can’t do arithmetic outside of
(( ))or$(( ))(orlet, but(( ))is preferred)