0

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:~$ 

4 Answers 4

2

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.

1

! 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.

1

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'.

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .