Andy Andy - 5 months ago 38
Bash Question

\! In Bash Commands

What is the function of

in a bash command?

For example, I notice that this command below will differ in behavior with

find subdir -lname 'test*' \! -newer somethinghere

Google searching does not appear to bring up anything specifically related to
except for command line formatting.

Answer Source

Putting a backslash before a character escapes it, preventing it from being parsed as syntax. Thus, \! is a terser equivalent to '!' -- it ensures that find is passed ! as an argument, without the shell interpreting it in any way.

Without either of these, if [[ $- = *H* ]] (which is true in an interactive shell and by default), and if histchars is unmodified from its default value, ! triggers history expansion. This is per the bash man page's QUOTING section:

When the command history expansion facilities are being used (see HISTORY EXPANSION below), the history expansion character, usually !, must be quoted to prevent history expansion.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download