Re: [Hampshire] Regular Expressions

Top Page

Reply to this message
Author: Bob Dunlop
Date:  
To: hampshire
Subject: Re: [Hampshire] Regular Expressions
Hi,

> However, in bash on my Debian machine:
>
> chris@T42:~$ echo "Don't do that!"
> bash: !": event not found
>
> Why is the ' in Don't protected by ", while ! is not? Or am I missing
> something?


Yet if you put that command in a script it will work as expected.
Even more puzzling :-)

It's because Bash has included a Cshellism and uses ! to introduce a
history expansion. History expansion is turned on by default for
interactive shells but not for scripts.

To turn history expansion off and get the result you expect.

$ set +o history
$ echo "Don't do that!"
Don't do that!


Turning history expansion on inside scripts will get you fired from
any company where I have that option.
-- 
        Bob Dunlop