#!/bin/sh SSH_ORIGINAL_COMMAND='publish x y z --foo --bar="hey, you! bada boom?" --flag="white space" || echo rm -irf /tmp/foo' # pick flags with string type parameters _flag=$(echo "$SSH_ORIGINAL_COMMAND" | sed -n 's/.*--flag="\([a-zA-Z0-9 _-]*\)".*/\1/gp') # bar allows a few character more... _fbar=$(echo "$SSH_ORIGINAL_COMMAND" | sed -n 's/.*--bar="\([a-zA-Z0-9?!, _-]*\)".*/\1/gp') # remove string type parameters that aren't known _args=$(echo "$SSH_ORIGINAL_COMMAND" | sed 's/--[a-zA-Z0-9_-]*="[a-zA-Z0-9 _-]*"//g') for _var in $_args do case $_var in publish) command="_publish" ;; --foo) _foo=1 ;; *) _other="$_other $_var" ;; esac done # for whatever this is for... _sanitized="$(echo "$_other" | tr -d '\|;!/\\?&')" echo "command: $_command" echo "flag: $_flag" echo "fbar: $_fbar" echo "foo: $_foo" echo "other: $_other" echo "other (sanitized): $_sanitized" if [ "$_command" == "publish" ] then echo "Let's publish something..." fi