summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xshell27
1 files changed, 17 insertions, 10 deletions
diff --git a/shell b/shell
index 5c1e28a..7c8f8fe 100755
--- a/shell
+++ b/shell
@@ -4,7 +4,7 @@
# Author: Peter Wu <lekensteyn@gmail.com>
hidw() {
- local hiddev arg bytes fillchar length oIFS
+ local hiddev arg bytes fillchar length oIFS actualArgs
hiddev=$1; shift
bytes=()
@@ -24,11 +24,10 @@ In this case, the message is padded with '0xff'.
The data can also be interleaved with chars by starting an argument
with a underscore (_). For example, "_foo" is equivalent to "66 6f 6f".
+A colon can also be used as separator, the previous hidw example is
+equivalent to:
-If only a single argument is given, the commands may be separated by
-colons. The previous hidw example is equivalent to:
-
- hidw /dev/hidraw0 10:ff:81:ff..
+ hidw /dev/hidraw0 10:ff 81:ff..
This function does not show replies, use the 'read-dev-usbmon' program
instead.
@@ -41,11 +40,19 @@ HELP
return 1
fi
- # Support ":" as separator if there is only a single argument. This makes
- # it easier to work with tshark output, and does not break "_:" arguments.
- if [ $# -eq 1 ]; then
- oIFS="$IFS"; IFS=:; set -- $*; IFS="$oIFS"
- fi
+ # Support ":" as separator, but ignore string arguments (_...).
+ actualArgs=()
+ for arg; do
+ if [[ $arg != _* ]] && [[ $arg == *:* ]]; then
+ # Strip leading+trailing such that "11:02: 83 01" is still valid.
+ arg="${arg##:}"
+ arg="${arg%%:}"
+ oIFS="$IFS"; IFS=:; actualArgs+=( $arg ); IFS="$oIFS"
+ else
+ actualArgs+=( "$arg" )
+ fi
+ done
+ set -- "${actualArgs[@]}"
for arg; do
# clear the fill char, makes only sense as last argument