key detection in a script

Heloo every one
I want to write a script that detects a key press and mouse click and movement,but I dont know how.
The second one is I want to run myscript without writing the shell ie not "sh script.sh" but "script.sh"
Can you help me out of here?
Thanks in advance.

You may want to check out Chris F.A Johnson's article Unix Review > Shell Corner: Mouse Reporting in a Shell Script

Hi Vino,
the website you told me is the best so far.Thanks!

Give your script execute permissions:

chmod +x script.sh

Note that if it is in the current directory (or any directory not in your PATH), you will have to tell the shell where to find it, e.g.:

./script.sh

What I wanted is to run the shell script program like any command just typing the omly the name not with an extension like .sh and preceeding the name of the shell i.e
Not- sh filename.sh
But- filename
Thanks.

If you don't want an extension, don't name the file with one.

If you want to type just the name of the file to execute it, give the file execute permissions:

chmod +x filename

I think you are mixing concepts.

File extensions have no meaning to the OS in UNIX, as they have in Windows. You could name your script whatever you want. But, in order to run it, as cfajohnson has told you, you have to set exec perms.

On the other hand, what you want is to avoid the use of either "sh" before the name of the script, and the use o "./" after it. To do so, you have at least two possibilities:

  • Add the directory which contains the binary to your PATH variable.
  • Copy or link it in one directory that's already in your PATH.

Regards.

As for the second part of your question enoch99:
Try this one:

#!/bin/sh
script content

if you execute this (./scriptname) and it is executable, then it should be executed using #!/bin/sh

you can put the file "script.sh" in /usr/bin .But you will need to have root permissions. you can do that by
sudo mv (or mv -i or cp -i to be safe) script.sh /usr/bin
and then enter your password when prompted.
Any program you have, even a simple c program executable you create can be run by just typing the executable name if it is present in /usr/bin . you can even remove the .sh extension if you want to i guess.I am just an amateur user of UNIX with hardly an year of experience.My apologies for any mistakes.

That's not a good place to put it. That should contain only system-provided commands. The better place is /usr/local/bin, or, if it's just for your own use, $HOME/bin.

It can be run by just typing the executable name if it is present in ANY directory in your $PATH.