I don't think this is a problem with your function (or, more accurately, I don't think this is a problem you can solve in your function). bash parses the command line (including interpreting quoted strings, various bracket expressions, etc) before it calls your function -- before it even decides to call your function. So when you type something like gc fixed Greg's bug
, bash will require that you close the quoted string before it executes the function; when you type gc printf("%s", integervar) not a good idea
, bash will complain about the parentheses and never even get to the point of deciding what command/function/whatever was being requested.
I presume the point of using $*
was to avoid having to quote the memo on the command line, but that only avoids having to quote spaces in the message. If the message contains other shell metacharacters, you must quote or escape them appropriately:
gc "fixed Greg's bug"
gc 'printf("%s", integervar) not a good idea'
gc 'fixed this & deferred that'