首页 \ 问答 \ 如何阻止bash for循环执行空列表(How to stop a bash for loop from executing for an empty list)

如何阻止bash for循环执行空列表(How to stop a bash for loop from executing for an empty list)

我使用一个简单的bash脚本从FTP服务器读取文件,转换为dos格式,然后移动到另一个文件夹:

#!/bin/bash

SOURCE="$1"
DESTINATION="$2"

# Use globbing to grab list of files
for x in $1/*.txt; do
 f=$(basename $x)
 todos $x
 echo "Moving $x to $DESTINATION/$f"
 mv $x $DESTINATION/$f
done

一个非常简单的问题 - 当没有要移动的txt文件时,如何停止循环执行?


I am using a simple bash script to read files from an FTP server, convert to dos format and then move to another folder:

#!/bin/bash

SOURCE="$1"
DESTINATION="$2"

# Use globbing to grab list of files
for x in $1/*.txt; do
 f=$(basename $x)
 todos $x
 echo "Moving $x to $DESTINATION/$f"
 mv $x $DESTINATION/$f
done

A really simple question - how do I stop the loop executing when there are no txt files to be moved?


原文:https://stackoverflow.com/questions/50711230
更新时间:2023-06-25 11:06

最满意答案

您的一个参数与列名称相同:AGENCYNO。 由于范围界定的方式,这评估为1=1 。 这就是为什么提供参数唯一名称的好习惯,例如通过在p_前加上它们。

你应该找到

AND c.PERIODE = p_period AND c.AGENCYNO = p_agencyNo

返回所需的一行。 严格来说,您不需要将period名称更改为p_period因为它已经与periode区分开来。 但一致性是软件工程的一个优点。


One of your parameters has the same name as the column: AGENCYNO. Because of the way scoping works this evaluates to 1=1. This is why it is good practice to give parameters unique names, for example by prepending them with p_.

You should find that

AND c.PERIODE = p_period AND c.AGENCYNO = p_agencyNo

returns the desired one row. Strictly speaking you don't need to change the name of period to p_period because it is already distinguished from periode. But consistency is a virtue in software engineering.

相关问答

更多
  • 查看第一个查询的解释计划。 我怀疑有一个错误,并且查询计划可能会显示如何进行无效重写。 Have a look at the explain plan for the first query. I suspect there is a bug, and the query plan may show how an invalid rewrite is being done.
  • 改为使用它: if (window.getComputedStyle(document.getElementsByTagName('body')[0]).cursor == 'pointer') Use this instead : if (window.getComputedStyle(document.getElementsByTagName('body')[0]).cursor == 'pointer')
  • Oracle Date包含的信息多于显示的信息:小时,分钟和秒。 如果你只对日期部分感兴趣,你应该使用trunc() order by trunc(MODIFIED_DATE) desc, CITY asc Oracle Date contains more information than displayed : hour, minutes and second. If you are only interested in the date part you should use trunc() ord ...
  • ToList()不能返回null但是空列表: if (_getData.Any()) { foreach (var e in _getData) { // some logic here to update the event etc } } else { // some logic to create an event } ToList() can't return null but empty list: if (_getData.Any()) { fore ...
  • 对于延迟回复此事,我深表歉意。 要记住的一件事是WaitUntilReady正在监视浏览器的“Ready”标志。 一旦浏览器完成主HTML页面(例如MyPage.html)以及任何引用的资源(图像,css文件,js文件等),就会设置此标志。 它没有考虑在加载页面后由于JavaScript获得控制而启动的任何Ajax回发。 Ajax Postbacks(通常在从Web服务器获取数据时通过某种类型的旋转圆圈直观显示)可能导致在WaitUntilReady将控制权返回到测试代码后很长时间内修改DOM。 如果设置执 ...
  • 它是哪种形式的版本? 如果它抱怨LEFT JOIN ,那可能是6i或什么的。 以前的(非常陈旧的)表单版本的PL / SQL引擎并不完全遵循数据库的PL / SQL引擎,因此并非所有工作在数据库中的东西都在Form中工作。 因此,我建议你尝试使用旧的Oracle外连接运算符(+)。 此外,如果BDATE列的数据类型是DATE ,则应该使用DATE值而不是字符串。 '01-Jul-2017'是一个字符串。 DATE '2017-07-01'是日期(文字)。 最后,说你的代码在SQL * Plus中工作正常 - ...
  • 您的一个参数与列名称相同:AGENCYNO。 由于范围界定的方式,这评估为1=1 。 这就是为什么提供参数唯一名称的好习惯,例如通过在p_前加上它们。 你应该找到 AND c.PERIODE = p_period AND c.AGENCYNO = p_agencyNo 返回所需的一行。 严格来说,您不需要将period名称更改为p_period因为它已经与periode区分开来。 但一致性是软件工程的一个优点。 One of your parameters has the same name as the ...
  • 试试以下: WebDriverWait wait = new WebDriverWait(dr, 30); wait.until(ExpectedConditions.jsReturnsValue("return document.readyState==\"complete\";")); void waitForLoad(WebDriver driver) { ExpectedCondition pageLoadCondition = new ExpectedC ...
  • 如果您只想构建一个逗号分隔的结果字符串,那么有很多更容易的方法。 一种直接的,天真的方式,不依赖于任何神奇的STUFF功能就是这种模式: DECLARE @result varchar(max); SET @result = ''; SELECT @result = @result + ',' + ColumnValueToUse FROM MyTable WHERE PRINT @result; 然后你可以剥掉第一个逗号。 结果将是“MyTable”表中“ColumVal ...
  • 在第二个查询中,您有一个外部联接。 在第一个查询中,您没有任何类型的连接; 你只需要从t中选择一个where子句,其中t.id之后有一个(+)。 我不知道为什么语法不会返回错误; 但是当t中不存在d.id时,该子查询不返回任何行,这就是当更新值应该是标量子查询的输出时更新的工作方式:如果子查询没有返回任何行,则update语句将更新NULL字段。 你没有要求一种不同的方式来使更新工作,但如果你想看到一个,这里就是。 毫无疑问,你知道如何做到这一点; 为其他论坛成员的利益提供它。 update d_dim ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)