shell 基本语法测试

本文介绍了Shell脚本中的一些基本语法,包括检查文件是否存在、查找网络接口eth0、循环打印'hello'以及使用for循环打印序列数字。通过示例函数`if_find_file`、`if_find_eth0`、`while_print_hello`和`for_print_num`,详细展示了如何在脚本中运用这些语法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#! /bin/bash


if_find_file(){
if [ -e /home/allen/test/shell_test/echo.sh ]
then
echo "file exit......"
else
echo " can't find this file......"
fi
}


if_find_eth0(){
#ifconfig | grep ppp0 
ifconfig | grep eth0 >> /dev/null 
if [ "$?" == "0" ]
then
echo "find etho......"  
else
echo "Don't find eth0......" 
fi
}


while_print_hello(){
count=0
while [ $count -le 2 ]
do
echo "hello......"
#((count++))
let "count+=1"
sleep 0.01
done
}


for_print_num(){
for x in one two three
do
echo $x
sleep 1
done
for num in $(seq 1 3)
do
echo $num
sleep 0.000000001
done
}


main(){
# [ ! -e /home/allen/test/shell_test/echo.sh ] && { echo have file 
#} 
[ -e /home/allen/test/shell_test/echo.sh ] && { echo have file;} 
# if_find_file
# if_find_eth0
# while_print_hello
# for_print_num
}


main
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值