未找到bash输出命令(bash output command not found)
我面临下面的问题,我已经创建了上述条件,但是当我选择y是的时候,一切都很好,但是当我选择n时,我得到了令人讨厌的错误输出:输出:你同意是(y)还是不是(n)n。 / myscript:[n:未找到命令
myscript是我的脚本的名字代码在这里:
echo "Do you agree yes (y) or not (n)" read answer if ( [ "$answer" = 'y' ] || ["$answer" = 'Y' ]); then echo -e “ output for y” done else echo -e " output for n " exit 1;
任何想法如何摆脱输出并解决问题? 谢谢
Im facing following problem I have created mentioned condition, but when I choose y for yes everything is ok, but when I choose n for not I get annoying error output: output : Do you agree yes (y) or not (n) n ./myscript: [n: command not found
myscript is the name of my script Code here:
echo "Do you agree yes (y) or not (n)" read answer if ( [ "$answer" = 'y' ] || ["$answer" = 'Y' ]); then echo -e “ output for y” done else echo -e " output for n " exit 1;
Any idea how can I get rid of the output and fix the problem ? thanks
原文:https://stackoverflow.com/questions/9831768
最满意答案
当你意识到你只需要使用assertThat时,很多混乱就消失了。 这个断言只是做所有其他人做的事情; 它以一种更好的方式来实现它。
不,订单并不重要。 最后,这是关于匹配两个值。 如果这两个值是相同的,你不在乎。
唯一的问题是:如果您反转了数值,那么修复破损的测试可能会更困难 - 因为您应该更好地理解实际值与预期值之间的差异。
最后:使用assertThat时有一个简单的帮助器。 它需要A(ctual),然后E(预期)。 非常按字母顺序。
A lot of that confusion goes away when you realize that you only need to use assertThat. This assert simply does what all the others do; and it does it in a much better way.
And no, the order doesn't really matter. In the end, this is about matching two values. If the two values are identical, you don't care.
The only problem: if you reverse values, then fixing broken tests might be harder - as you should better understand the difference between the actual and the expected value.
Finally: there is a simple helper when using assertThat. It wants A (ctual), then E(expected). Very much in alphabetical order.
相关问答
更多-
提供此功能的基础匹配器是org.hamcrest.core.IsSame 。 它有方便的方法将它隐藏在org.hamcrest.Matchers#sameInstance (如你所提到的)和org.hamcrest.CoreMatchers#sameInstance 。 无论您使用哪个主要是偏好问题。 就个人而言,我更喜欢从CoreMatchers静态导入,只是因为它“更苗条”: import static org.hamcrest.CoreMatchers.sameInstance; import sta ...
-
配置Gradle以使用JUnit,Mockito,Hamcrest和Espresso(Configuring gradle to use JUnit, Mockito, Hamcrest and Espresso)[2022-06-28]
我意识到这一点,在Hamcrest 1.1中,它只是在hamcrest-integration而不是hamcrest-core 。 我改变了我的构建文件,它现在都在工作: androidTestCompile files( 'libs/espresso-1.1.jar', 'libs/testrunner-1.1.jar', 'libs/testrunner-runtime-1.1.jar' ) androidTestCompile( 'org ... -
滥用hamcrest hasItems(Misuse of hamcrest hasItems)[2023-07-19]
hasItems(notExpected...)只会匹配current如果notExpected中的所有元素也都是current 。 所以与线 assertThat(current, not(hasItems(notExpected...))); 你断言current不包含notExpected 所有元素 。 一个解决方案来断定current不包含来自notExpected 任何元素 : assertThat(current, everyItem(not(isIn(notExpected)))); 然后 ... -
NoSuchMethodError与Hamcrest 1.3和JUnit 4.11(NoSuchMethodError with Hamcrest 1.3 & JUnit 4.11)[2022-12-02]
这个博客帮助我解决了同样的问题: https://tedvinke.wordpress.com/2013/12/17/mixing-junit-hamcrest-and-mockito-explaining-nosuchmethoderror/ 在Mockito和Junit的依赖关系中,作者补充说:junit junit 4.11 ... -
Hamcrest比较收藏(Hamcrest compare collections)[2023-06-24]
如果你想要断言这两个列表是一样的,那就不要使Hamcrest变得复杂: assertEquals(expectedList, actual.getList()); 如果您真的打算执行不受秩序影响的比较,可以调用containsInAnyOrder varargs方法并直接提供值: assertThat(actual.getList(), containsInAnyOrder("item1", "item2")); (假设您的列表为String ,而不是Agent )。 如果你真的想用List的内容来调用 ... -
junit提供了一个名为assertThat()的新的检查断言方法,它使用Matchers,并且应该提供更可读的测试代码和更好的失败消息。 为了使用它,junit中包含一些核心匹配器。 您可以从基础测试开始。 如果你想使用更多的匹配器,你可以自己写或者使用hamcrest lib。 以下示例演示了如何在ArrayList上使用空匹配器: package com.test; import static org.hamcrest.Matchers.empty; import static org.hamcre ...
-
当你意识到你只需要使用assertThat时,很多混乱就消失了。 这个断言只是做所有其他人做的事情; 它以一种更好的方式来实现它。 不,订单并不重要。 最后,这是关于匹配两个值。 如果这两个值是相同的,你不在乎。 唯一的问题是:如果您反转了数值,那么修复破损的测试可能会更困难 - 因为您应该更好地理解实际值与预期值之间的差异。 最后:使用assertThat时有一个简单的帮助器。 它需要A(ctual),然后E(预期)。 非常按字母顺序。 A lot of that confusion goes away ...
-
如何使用JUnit和Hamcrest测试.equals()方法(How to test an .equals() method using JUnit and Hamcrest)[2023-05-26]
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; ... assertThat(list1, equalTo(list2)); import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; ... asse ... -
这取决于您正在使用的JUnit的版本。 你可以通过查看lib/junit/junit/jars来检查这一点。 我认为默认情况下这是4.10。 如果是这样,请升级到4.11。 你可以通过在BuildConfig.groovy中明确指定它来做到这一点我相信: dependencies { test 'junit:junit:4.11' test 'org.hamcrest:hamcrest-all:1.3' } 为了解释,在4.11之前,一个版本的hamcrest库包含在JUnit发行版中。 4.11 ...
-
查看IsIterableContainingInAnyOrder.containsInAnyOrder的javadoc 。 假设您没有尝试将Matcher传递给此方法,您应该将数组(或varargs)传递给此方法,例如: assertThat(actual, IsIterableContainingInAnyOrder.containsInAnyOrder("qwe", "asd", "bc")); 要么 assertThat(actual,IsIterableContainingInAnyOrder.c ...