From 21e8aa2522da88723b4e046bdc9366f445dee103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Sch=C3=B6ttl?= Date: Sat, 23 Jan 2016 22:03:46 -0800 Subject: [PATCH] Fixed long-option argument parsing Arguments of long-options (e.g. --program-flags='--foo=bar') may contain equal sign characters (=). Before this fix, these kind of options were split up into "program-flags" and "--foo" removing the last part of the argument. This was because only the first two colums from `awk -F= ...` were used. Now these kind of options will be split up correctly using Bash parameter expansion: "program-flags" and "--foo=bar". See man bash > Parameter Expansion for details. Tested with: sudo cp tdrop /usr/bin/tdrop tdrop -W --program-flags='-e tmux --role=tdropwindow' termite tdrop -W -f '-e tmux --role=tdropwindow' termite tdrop --normal-window -f '-e tmux --role=tdropwindow' termite It also works for boolen long-option flags without argument. In this case both OPTION and OPTARG are set to the long-option name. Boolean options don't use the OPTARG so it doesn't matter. --- tdrop | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tdrop b/tdrop index 32dedce..0c5d978 100755 --- a/tdrop +++ b/tdrop @@ -91,8 +91,8 @@ do a) auto_detect_wm=true;; m) monitor_aware=true;; -) - OPTION=$(echo "$OPTARG" | awk -F '=' '{print $1}') - OPTARG=$(echo "$OPTARG" | awk -F '=' '{print $2}') + OPTION=${OPTARG%%=*} + OPTARG=${OPTARG#*=} case $OPTION in height) height=$OPTARG;; width) width=$OPTARG;;