Check what shell interpreter the system has: cat /etc/shells
CentOs uses bash by default: echo $SHELL
Getting Started with Shell Scripting
1. Script format:
The script should start with #!/bin/bash to specify the parser
Create the first script hello.sh:
# 编写脚本 也可以不写.sh指定后缀
vim hello.sh
#!/bin/bash
echo hello world
echo "hello world bash " >> lxw.txt
The first line #!/bin/bash is used to specify the parser bash
The second line outputs a line hello world
The third line appends hello world bash to the lxw.txt file
Execute the script:
bash script name
sh script name
filename execute script ./hello.sh
It will be found that the permissions are not enough, because the current user permissions are read and write rw- , and there is no executable permission x
We need to change the script file permissions
# 方式一hello.sh 脚本的+x 权限
chmod +x hello.sh
# 方式二 二进制更改
chmod 744 hello.sh
It is found that after changing the permissions, the script name can be used to execute the script directly
source hello.sh . hello.sh execution script
The . script name here is different from the previous ./. ./ is a relative path. The . here is the shell embedded command type source
The difference between source and bash sh