Before writing this file, I have not written a shell, I have only modified it before, I have seen the shell, haha
You can take a look at this blogger's simple explanation of the shell, which is very well written.
https://blog.csdn.net/miss1181248983/article/details/81278937
1. Create a file, preferably under / usr / local / sbin. I heard that it is convenient for management and subsequent maintenance.
//创建文件命令
sudo touch test.sh
2. Add content to the file
The first line should #!/bin/bash
start with, indicating that the file uses bash
syntax
#
Remarks
Everyone else who has learned programming knows it at a glance, although I have never used php, haha.
#!/bin/bash
## This is my first shell script.
## Writen by homey 2019-11-13
date
echo "Hello World!"
3. Start running the shell script below
First of all, you will encounter permissions problems, as follows
cosun@cosun:/usr/local/sbin$ ./test.sh
-bash: ./test.sh: 权限不够
Now that the authority is not enough, then we will give it the authority, how to give it? as follows
cosun@cosun:/usr/local/sbin$ sudo chmod +x test.sh
Then the problem is coming, we usually execute chmod 755 and other commands + digital permissions, for example, this has read and write permissions. What permissions is chmod + x?
chmod +x的意思就是给执行权限,只有命令才可执行,所有可理解为给脚本执行权限。
then
cosun@cosun:/usr/local/sbin$ ./test.sh
2019年 11月 13日 星期三 09:43:39 CST
Hello World!
how about it? Will it be a shell script.