From ac981508f798ad7f729a47609dee5536b6f5e3e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Thu, 2 Apr 2020 16:17:21 +0200 Subject: [PATCH] Fix incorrect handling of flags Previously, arguments were examined by a for loop, but this loop is not affected by the `shift` commands executed inside of it. Because the loop always advances one argument further on each iteration, this bug goes unnoticed with the `--portrait` option (`shift` is called once, which matches the behavior of the loop). However, handling of the `--destination` argument is broken because of that (`shift` is called twice but the loop only advances one argument). This commit replaces the `for` loop by a `while` loop which always examines the next argument and properly takes `shift`s into account. This is based on the following SO answer: --- reStream.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/reStream.sh b/reStream.sh index 8031b6b..efafff6 100755 --- a/reStream.sh +++ b/reStream.sh @@ -5,9 +5,8 @@ ssh_host="root@10.11.99.1" # remarkable connected trough USB landscape=true # rotate 90 degrees to the right # loop through arguments and process them -for arg in "$@" -do - case $arg in +while [ $# -gt 0 ]; do + case "$1" in -p|--portrait) landscape=false shift