Bash, sometimes you suck

So, I’m trying to pass a ! character to a shell command. Should be simple right?

Not so much.

twit --post 'OMG...I'm out of coffee...work stoppage!'
bash: !': event not found

Huh? Oh yeah, in the fine tradition of crappy shells like csh, bash uses ! to re-run commands from the command history. But you’d think that in a single-quoted string it wouldn’t interpret that, it would just pass it into the command I’m running. Nope.

Can I escape it with a backslash? You bet.

$ echo "foobar\!"
foobar\!

K, still not what I wanted.

Simple solution, don’t use bash.

sh twit --post 'OMG...I'm out of coffee...work stoppage!'

Works fine in a POSIX mode.

Am I missing something? Is there a simpler way to get what I want? This blows the 80/20 rule totally.

Advertisements

Post a Comment

Required fields are marked *

*
*

%d bloggers like this: