A prominent secular writer who spoke out for freedom dies after being attacked in the Bangladeshi capital, a police official says.