Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
a@ubuntu:~$ 
share|improve this question
add comment

4 Answers 4

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
add comment

! 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
add comment

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:

      #!/bin/bash
      $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
add comment

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
add comment

Your Answer

 
discard

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.