This is very strange indeed. The steps you describe should have worked, so there must be some small error in your environment or the execution of those steps. There are some things you can do to help diagnose this:
CHECKING FOR CONTROL CHARACTERS
What you've documented looks fine, as long as there are no typos or control characters. You should check by typing:
cat -vt ./test
If you see any unexpected extra text that could explain the problem. For example, "^M" at the end of a line would indicate that your editor saved the file in Windows format.
REGENERATING THE FILE RELIABLY
To create a known-good ./test2, copy-paste the commands below:
`which bash`
printf "#\!`which sh`\necho HELLO\n" > ./test2
chmod +x ./test2
./test2
exit
CHECKING WHICH COMMAND CAN NOT BE FOUND
If you type...
./ajio
...do you get exactly...
./ajio: Command not found.
...as you described with ./test? I just made up the name ajio so it shouldn't exist. If they messages match then it doesn't really tell you anything new. But if the messages differ, that confirms that ./test was at least found and executable.
It's also possible that your version of sh is trying to tell you not that test can't be found, but that while running test some command the shell tried to run couldn't be found. That shouldn't be the echo command, as with most shell implementations that will be an internal command, implemented inside the shell. But, the shell may run an initialisation script containing a line specifying a command it can't run. If you run man sh, it will tell you about all the different startup files that your shell might try to run. These can be different from those used when you start the shell interactively. But, as a b
answered 2010-10-06T01:15:52.800