basic port of bash code to python