Programmes are rarely written for specific hardware, they are written for the OS. Just because the architechtures are compatible (in that they both have the same instruction sets) doesn't mean that applications will work natively. If that were the case, we could all run Linux apps on Windows, and vice versa. The programmes are written to a specific kernel, and so will either need recompiling for another kernel, or will need an "emulation" package to run them semi-natively.
If you look at a programme, such as, /bin/echo you will notice that it contains the characters ELF near the beginning - this is an ELF binary. Many OSs use ELF binaries, but they are not necessarily compatible - for example, a binary executable programme written for AROS on x86 hardware will not work natively under Linux even though they are both x86 and they are both ELF binaries. It was written for AROS, not Linux. As mentioned above, shell scripts are different. Since these are simply text files, they should be executable by any OS that runs the correct interpreter (for want of a better way to explain it), such as BASH or CSH.