Write the Hello World script and execute the script
Two methods
1, ls-a view all the files
2. mkdir test.sh Create a file named test.sh
3, CD test.sh into test.sh this file
4, Vim test.sh open vim and enter into test.sh this file
5, I (insert insertion, editing)
6. Write script
#!/bin/sh
#echo "123456" This behavior comment
echo "Hello World" echo for output command, the Hello World field will appear after the Echo Hello World return is written separately
7. ESC Exit Vim edit mode
8, input: After wq! Save the file and exit vim
9. After SH test.sh, Hello World appears.
Or
9. cd. Go back to the root directory
10, CHOMD +x./test.sh This step is test.sh this script has execute permissions
11./test.sh execution script appears Hello World
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. To run the bash script this way, the first line must be written so that the system can find the correct interpreter.
As an interpreter parameter, this runs the interpreter directly, whose arguments are the file names of the shell scripts, such as:
$/bin/sh test.sh
$/bin/php test.ph
Read command
1, ls-a view all the files
2. mkdir test2.sh Create a file named test.sh
3, CD test2.sh into test2.sh this file
4, Vim test2.sh open vim and enter into test.sh this file
5. Write script
#!/bin/bash
# Author:mozhiyan
# Copyright (c) http://see.xidian.edu.cn/cpp/linux/
# Script follows here:
echo "What's your name?" Enter a name manually, such as: WJ
Read person
echo "Hello, $PERSON" appears after carriage return as Hello WJ similar to scanner (scan) keyboard input
Shell Getting Started notes