1753569 Members
6047 Online
108796 Solutions
New Discussion юеВ

Shell command execution

 
SOLVED
Go to solution
SGK
Occasional Advisor

Shell command execution

Hi,

The following command is not working:

[root@localhost tmp]# a=`echo Hello!`
-bash: !`: event not found

The document says "exclamation mark" triggers the Bash "history mechanism."

Can someone explain in detail?

TIA.
3 REPLIES 3
Jeroen Peereboom
Honored Contributor

Re: Shell command execution

L.S.

try
a='Hello!
or a=`echo "$SomeVar"'Hello!'`

The single quotes form a literal string.
Check bash man page for QUOTING.

JP
Alexander Chuzhoy
Honored Contributor

Re: Shell command execution

You must prepend the exclamation mark with a backslash
the following will work:
a=`echo Hello\!`
Ivan Ferreira
Honored Contributor
Solution

Re: Shell command execution

-bash: !`: event not found

You get this error because in the bash shell if you run !something, the shell tries to find the last command that starts the word "something", that is, the ! is a special character for bash.

For example:

ls /usr/share/doc
echo "Hello"
!ls

The last command will run ls /usr/share/doc again.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?