diff --git a/dist/tools/usb-serial/ttys.py b/dist/tools/usb-serial/ttys.py index 36cc36f214..1a98ddd0cb 100755 --- a/dist/tools/usb-serial/ttys.py +++ b/dist/tools/usb-serial/ttys.py @@ -213,11 +213,14 @@ def print_ttys(args): ttys.append(tty) if args.most_recent: - most_recent = ttys[0] - for tty in ttys: - if tty["ctime"] > most_recent["ctime"]: - most_recent = tty - ttys = [most_recent] + if len(ttys) > 0: + most_recent = ttys[0] + for tty in ttys: + if tty["ctime"] > most_recent["ctime"]: + most_recent = tty + ttys = [most_recent] + else: + ttys = [] print_results(args, ttys)