02 入门样例

2.1 入门hello world 脚本

[root@centos74 test]$ vim helloword.sh
[root@centos74 test]$ cat helloword.sh
#!/bin/bash
echo "Hello World"
[root@centos74 test]$ chmod a+x helloword.sh
[root@centos74 test]$ ./helloword.sh
Hello World

第一行#!/bin/bash是shebang机制要求的。第二行就是脚本内容了,我在centos环境下需要添加执行权限。

2.2 写一个简单的备份脚本

#!/bin/bash
tar -cZf /var/my-backup.tgz /home/me/