Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried code from this question and for some reason they do not work, why and how to fix them?

a@ubuntu:~$ echo "#!/bin/sh" > ~/bin/run_linx_program
bash: !/bin/sh": event not found
a@ubuntu:~$ echo "$1 "\`wine winepath -u \"$2\"\`\"" >> ~/bin/run_linx_program
> ?
> ^C
share|improve this question
up vote 2 down vote accepted

I've fixed the original answer (and I've tested it this time):

mkdir -p ~/bin/
echo '#!/bin/sh' > ~/bin/run_linx_program
echo '$1 "`wine winepath -u "$2"`"' >> ~/bin/run_linx_program
chmod a+x ~/bin/run_linx_program

I forgot that ! gets interpreted inside "s. I should have used 's. ! starts a history substitution match and that wasn't what I was going for.

share|improve this answer

! has a special meaning in bash:

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.

There are two ways to prevent history exspansion, either by escaping the ! with a backslash, or by using single quotes:

a@ubuntu:~$ echo "#\!/bin/sh" > ~/bin/run_linux_program
a@ubuntu:~$ echo '#!/bin/sh' > ~/bin/run_linux_program

In complex constructs, try to avoid the " (double quote) char and use the single one instead ('):

echo "$1" '"$(wine winepath -u "'$2'")"' >> ~/bin/run_linux_program

I've replaced the backticks by $( and ) to make the line more clear.

share|improve this answer

This is a bit of a round-about way of doing things. The first like creates a file and writes #!/bin/sh to it, the second one appends something else to the file.

  • To get this working

    1. Create the directory bin in your home directory, either in Nautilus or by typing

      mkdir -p ~/bin
    2. Create a new file ~/bin/run_linx_program (where ~ is shorthand for "your home directory") and put these lines into it:

      $1 "`wine winepath -u "$2"`"

      You can create the file by doing nano ~/bin/run_linx_program, or you can use the Text Editor.

    3. Run chmod a+x ~/bin/run_linux_program to make the file executable, alternatively you can right click the file, open the properties, go to Permissions and set 'executable'.

share|improve this answer

Unless you actually use or need history expansion, I recommend just turning it off by adding the line

set +H

in your ~/.bashrc. I've done that and am quite happy to never be bothered by event not found messages again.

Regardless, history expansion is only enabled for interactive shells, so it won't affect scripts.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.