交互式定义变量脚本

[root@oldboy ~]# vim panduan.sh
#!/bin/bash

read -p '请输入需要判断的目录或文件:' f   自定义一个变量

ls -l $f &> /dev/null

if [ $? -eq 0 ] ;then            echo $? 查看上一个命令是否执行成功,-gt 大于
     echo "$f 目录或文件存在"      -eq 等于                             
else
     echo "$f 目录或文件不存在"
fi

[root@oldboy ~]# sh panduan.sh
请输入需要判断的目录或文件:2.
-rw-r--r--. 1 root root 20488 Apr  7 15:40 2.
[root@oldboy ~]# sh panduan.sh
请输入需要判断的目录或文件:/etc    (最好写绝对路径)

# 脚本中使用重定向
#!/bin/bash

. /etc/init.d/functions

read -p "请输入要检测的IP:" IP

ping -c1 -W1 $IP &>/dev/null   一秒钟ping一次,&

if [ $? -eq 0 ];then
        action "$IP" /bin/true >> /tmp/IP_OK.txt
else
        action "$IP" /bin/false >> /tmp/IP_FAILD.txt
fi

[root@oldboy ~]# vim dayinrizhi.sh
while true;do
   echo syy >> /var/log/messages
   sleep 3                         3秒追加一次 (绝对不能覆盖,无意义)
done
原文地址:https://www.cnblogs.com/syy1757528181/p/12813411.html