#!/bin/bash
cd /var/log
cat /dev/null > messages
echo "Logs Cleaned up."
包括Bourne shell(sh)、 Korn shell(ksh) 、Bourne Again Shell(bash)三种
包括 csh 、 tcsh 两种
#[root@localhost ~] # cat /etc/shells
法一
[root@localhost ~] # echo $SHELL
法二:
[root@localhost ~] # grep root /etc/passwd
1、脚本开头(第一行) 会以如下的形式指出由哪个解释器来执行脚本中的内容,如下
#!/bin/bash
或
#!/bin/sh
1、在/root/下创建该脚本,命名为 test.sh 2、关闭防火墙(firewalld) 3、关闭防火墙自启 4、设置Selinux安全模块为允许模式 5、修改主机名为test 6、查看当前时间 7、执行完后删除该脚本
#!/bin/bash
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
hostnamectl set-hostname test
date
echo "Execution completed !"
rm -rf /root/test.sh
#!/bin/bash
while [ 1 -gt 0 ]
do
sleep 1
echo 'Welcome to China !'
done
这里是利用while语句进行循环输出,注意 [] 中括号和数字之间一定要有空格,不能挨在一起,这里的 -gt 是指的大于,若1>0 条件成立,那么就执行
运算符 | 说明 |
---|---|
-eq | 检测两个数是否相等,相等返回 true。 |
-ne | 检测两个数是否不相等,不相等返回 true。 |
-gt | 检测左边的数是否大于右边的,如果是,则返回 true。 |
-lt | 检测左边的数是否小于右边的,如果是,则返回 true。 |
-ge | 检测左边的数是否大于等于右边的,如果是,则返回 true。 |
-le | 检测左边的数是否小于等于右边的,如果是,则返回 true。 |