C高级作业day4_0409

#!/bin/bash
echo "作业1"
read -p "请输入数组: " -a arr
read -p "请输入要查找元素: " key
((find=0))
for i in "${arr[@]}"
do
    if [ "$i" = "$key" ]
	then
        echo 找到
		((find=1))
        break
	fi
done
if [ "$find" = "0" ]
then
    echo "不存在:$key 不在数组中"
fi
ubuntu@ub

#!/bin/bash
echo "作业2"
read -p "请输入数组元素: " -a arr
read -p "请输入查找元素key: " key
for i in "${!arr[@]}"
do
    if [ "${arr[i]}" = "$key" ]
	then
        arr[i]="hehe"
        break
    fi
done

echo "替换结果:${arr[@]}"

#!/bin/bash
echo "作业3"
read -p "请输入数组: " -a arr
read -p "输入删除元素: " key

new_arr=()
found=0
for i in "${!arr[@]}"
do
    if [ "${arr[$i]}" = "$key" ] 
	then
		((index=i))
        break
    fi
done
unset arr[$index]
echo "删除后的数组:${arr[@]}"
ubuntu@ubuntu:~/homework/C_high$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值