使用shell判断文件夹中是否包含文件

#!/bin/bash

directory="/path/to/directory"
if [ $(ls -A $directory) ]; then
  echo "有文件"
  # 执行指定shell脚本
  sh /path/to/script.sh
else
  echo "没有文件"
fi

  

#!/bin/bash directory="/path/to/directory"if [ "$(ls -A $directory)" ]; thenecho"有文件"# 执行指定shell脚本 sh /path/to/script.sh elseecho"没有文件"fi
posted @ 2023-02-23 16:36  启豪  阅读(426)  评论(0编辑  收藏  举报