shell脚本的小实例

while [ 1 ];do
  read -p "输入正确数据集类型training、test:  " dstype
  read -p "输入正确业务类型defect、device、element、tower、environment、defect2、device2、element2、defect3:  " etype
  read -p "输入正确批次: " batchnum
  picnum=0
  no_picnum=0
  current_path=$(pwd) 
  if [ "$dstype" = "training"  ]; then
      cd "$current_path"
  #    cd "/datasets/train_project/ka3ffd2b8f1eea49a0a3a91a0ba60001b5"
  #    for i in $(find . -type d -name "${dstype}-data-*-${etype}")
      for i in $(ls |grep -w "${dstype}-data-.\{2,30\}-${etype}")
      do
  #      echo "$i/defect/$batchnum/"
        target_path="$current_path/$i/defect/$batchnum/images"
        if [ -d "$target_path" ]; then
          echo "目录存在$i/defect/$batchnum/"
          cd "$target_path" || exit
          num=$(find . -type f -iname "*.jpg" | wc -l)
          picnum=$((picnum + num))
        else
          echo "目录不存在$target_path"
        fi
        no_target_path="$current_path/$i/no_defect/$batchnum/images"
        if [ -d "$no_target_path" ]; then
          echo "目录存在$i/no_defect/$batchnum/"
          cd "$no_target_path" || exit
          no_num=$(find . -type f -name "*.jpg" | wc -l)
          no_picnum=$((no_picnum + no_num))
        else
          echo "目录不存在$no_target_path"
        fi
      done
      total_picnum=$((no_picnum+picnum))
      echo "训练批次$batchnum 图片数: $total_picnum"
  elif [ "$dstype" = "test" ]; then
  #    for i in $(find . -type d -name "${dstype}-data-*-${etype}")
      cd "$current_path" 
      for i in $(ls |grep -w "${dstype}-data-.\{2,30\}-${etype}")
      do
  #      echo "$i"
        target_path="$current_path/$i/images"
        if [ -d "$target_path" ]; then
          echo "目录存在$i"
          cd "$target_path" || exit
          num=$(find . -type f -iname "*.jpg" | wc -l)
          picnum=$((picnum + num))
        else
          echo "目录不存在$target_path"
        fi
      done
      echo "测试图片数: $picnum"
  else
      echo "输入错误数据集类型"
  fi
done

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Shell脚本是一种在Unix或Linux系统下编写的脚本语言,用于自动化和批处理任务。以下是几个Shell脚本的应用实例: 1. Hello World脚本:这是一个简单的Shell脚本,用于输出"Hello World!"的信息。 ``` #!/bin/bash echo "Hello World!" ``` 这个脚本通过echo命令输出了"Hello World!"的文本。 2. 杀死所有脚本:这个脚本用于通过进程名筛选并杀死所有影响系统负载的进程。 ``` #!/bin/bash ps aux | grep 指定进程名 | grep -v grep | awk '{print $2}' | xargs kill -9 ``` 这个脚本通过ps、grep和kill命令结合使用,找到指定进程名的进程并强制终止。 3. 对信号的处理:这个脚本用于拦截用户通过键盘或kill命令发送过来的信号,实现对信号的处理。 ``` #!/bin/bash trap 'echo "暂停10s"; sleep 10' 2 while : do echo "gogogo" done ``` 这个脚本使用trap命令拦截用户按下Ctrl C键发送的信号,并执行暂停十秒的操作。在这个脚本中,使用了无限循环来不断输出"gogogo"的文本。 这些是Shell脚本的一些应用实例,它们可以用于各种自动化和批处理任务,方便地完成一系列操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [100个实用的 Linux Shell 脚本经典案例](https://blog.csdn.net/qq_27706119/article/details/125812348)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [推荐超详细的5个Shell脚本实例](https://blog.csdn.net/Listen2You/article/details/100592404)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值