Shell timout code with preserving environment context