【Linux-shell】shell脚本基础语法练习

来源:互联网 发布:电脑网络维修上门 编辑:程序博客网 时间:2024/04/30 04:46

一直在学习,也一直在忘记,今天借助这篇博文,记录下自己学习过程中的一些最基础的东西!

这篇文章会不定期更新。

1、for

#!/bin/bash for i in {1..10}do    echo $idone

扫描目标网段中活动的ip

#!/bin/bash for ip in 192.168.1.{1..255} ;do    ping $ip -c 2 &> /dev/null ;     if [ $? -eq 0 ];    then        echo $ip is alive    fidone

2、if

#!/bin/bash# 判断当前用户是否为root if [ $UID -eq 0 ];then    echo You are root user.else    echo You are nothing.fi
0 0