首页 \ 问答 \ 未找到bash输出命令(bash output command not found)

未找到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
更新时间:2024-01-04 17:01

最满意答案

当你意识到你需要使用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 ...
  • 我意识到这一点,在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 ...
  • hasItems(notExpected...)只会匹配current如果notExpected中的所有元素也都是current 。 所以与线 assertThat(current, not(hasItems(notExpected...))); 你断言current不包含notExpected 所有元素 。 一个解决方案来断定current不包含来自notExpected 任何元素 : assertThat(current, everyItem(not(isIn(notExpected)))); 然后 ...
  • 这个博客帮助我解决了同样的问题: https://tedvinke.wordpress.com/2013/12/17/mixing-junit-hamcrest-and-mockito-explaining-nosuchmethoderror/ 在Mockito和Junit的依赖关系中,作者补充说: junit junit 4.11 ...
  • 如果你想要断言这两个列表是一样的,那就不要使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 ...
  • 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用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)