Open a text editor, create a new file with the extension sh (sh for Shell), and the extension does not affect script execution.
Enter some code:
- #!/bin/bash
- echo "Hello world!"
"#!" is a contract tag that tells the system what interpreter the script needs to execute, even if it uses a shell. The echo command is used to output text to a window.
There are two ways to run a shell script.
As an executable program
Save the above code as test.sh and CD to the appropriate directory:
chmod +x./test.sh #使脚本具有执行权限./test.sh #执行脚本
Note, be sure to write./test.sh, not test.sh. Run other binary programs also, the direct write Test.sh,linux system will go to the path to find there is not called test.sh, and only/bin,/sbin,/usr/bin,/usr/sbin, etc. in path, your current directory is usually not in path, So write test.sh will not find the command, to use./test.sh tells the system that it is looking in the current directory.
The above code executes the result
(Quoted from http://c.biancheng.net/cpp/view/6998.html)
Shell Foundation Learning Series One: first shell script