如果在目录中没有的文件,不要启动循环? [英] Do not start loop if there is no files in directory?

查看:123
本文介绍了如果在目录中没有的文件,不要启动循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,

我Solaris 10中运行bash

I am running BASH in Solaris 10

我也取决于CSV文件presence,在一个目录循环,下面的shell脚本。

I have the following shell script that loops in a directory depending on the presence of CSV files.

问题是这片code的是,它仍然没有即使是在该目录中没有的CSV文件一个循环,然后调用SQL加载器。

The problem is with this piece of code is that it still does one loop even if there is no CSV files in that directory and then calls SQL loader.

SQLLOADER然后生成一个日志文件,因为没有文件来处理,这是开始乱了我的目录中的日志文件填充它。

SQLLoader then produces a log file because there is no file to process and this is beginning to mess up my directory filling it with log files.

for file in *.csv ; 
do 
    echo "SQLLoader is reading : " $file
    sqlldr <User>/<Password>@<DBURL>:<PORT>/<SID> control=sqlloader.ctl log=$inbox/$file.log data=$inbox/$file
done

我如何阻止它进入一个循环,如果没有在$收件箱中的目录中没有的CSV文件

How do I stop it going into a loop if there is no CSV files in that directory of $inbox

推荐答案

说:

shopt -s nullglob

在你的循环。

这是不会默认,并说在* .csv文件当你没有任何匹配的文件它扩展为 *。csv格式

This is not the default, and saying for file in *.csv when you don't have any matching files expands it to *.csv.

文档报价:

nullglob

如果设置,bash允许没有匹配文件,这文件名模式拓展到一个空
  字符串,而不是自己。

If set, Bash allows filename patterns which match no files to expand to a null string, rather than themselves.

这篇关于如果在目录中没有的文件,不要启动循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆