Scotland held their nerves to record a famous victory against Bangladesh, having been reduced to 53/6 in the first innings.