Remove most bashisms from main script