There are two mistakes in your commands.
Your first mistake is that your file is not in a correct executable format. The first line of a shell script must start with
#!. If it does not start with those characters, it is not a shell script.
Some shells have workarounds for such incorrectly formatted shell scripts. But those workarounds are only in place when the script is started from a shell and not when the script is started from another program. Additionally different shells have different workarounds for incorrectly formatted shell scripts.
All in all that means relying on those workarounds will result in unpredictable behavior, and you should always include the
#! line. For example you could have typed:
echo '#!/bin/sh' > hello
echo 'say hello' >> hello
The other mistake is that you did not provide a path to the script when trying to execute it. You should have typed:
When you only typed
hello, the shell will search through the
PATH for the command. For security reasons
. is not in
PATH. If you regularly need to create shell scripts, it is a good idea to create a directory for those shell scripts and put that directory in your
PATH. I personally use
~/bin for both shell scripts and occasionally small compiled programs.