simpler method, again from http://unix.stackexchange.com/a/110877/1925