shell 编程学习笔记

序号内容备注
if

if [[]] 推荐使用双中括号。

--------------------------

-e 用于测试文件是否存在。
-f 用于测试文件是否为普通文件。--推荐使用

--------------------------

Linux08-shell编程之运算符_哔哩哔哩_bilibili
add

数字运输

`expr $a + $b`

$[a+b]

echo -eecho -e "\n"
caseecho "input number:"
echo "your input is:"
read num
case $num in
    1) echo 'you choose 1'
    ;;
    2) echo 'you choose 2'
    ;;
    3) echo 'you choose 2'
    ;;
    4) echo 'you choose 2'
    ;;
    *) echo 'you did not input number 1-4'
    ;;
esac
while

#!/bin/bash

# 初始化计数器
count=1

# 当 count 小于等于 10 时继续循环
while [ $count -le 10 ]; do
    echo "Count: $count"
    # 更新计数器
    count=$((count + 1))
done

--------------------------

#!/bin/bash

# 指定文件名
filename="example.txt"

# 使用 while 循环读取文件中的每一行
while IFS= read -r line; do
    echo "Line: $line"
done < "$filename"

--------------------------

#!/bin/bash

# 初始化计数器
count=1

# 当 count 大于 10 时停止循环
until [ $count -gt 10 ]; do
    echo "Count: $count"
    # 更新计数器
    count=$((count + 1))
done

--------------------------

#!/bin/bash

# 提示用户输入
echo "Enter 'exit' to quit."

# 读取用户输入
while true; do
    read -p "Input: " user_input
    if [ "$user_input" = "exit" ]; then
        echo "Exiting..."
        break
    else
        echo "You entered: $user_input"
    fi
done

--------------------------

#!/bin/bash

# 初始化计数器
count=1

# 当 count 小于等于 10 时继续循环
while [ $count -le 10 ]; do
    if [ $((count % 2)) -eq 0 ]; then
        # 如果 count 是偶数,则跳过本次迭代
        count=$((count + 1))
        continue
    fi
    echo "Odd number: $count"
    count=$((count + 1))
done

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yangkei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值