这个bash脚本如何导致无限循环?(How is this bash script resulting in an infinite loop?)
从一些谷歌搜索(我不是任何bash专家)我能够组合一个bash脚本,允许我运行测试套件并在运行时在底部输出状态栏。 它通常需要大约10个小时,状态栏告诉我通过了多少次测试以及失败了多少次。
它有时很好用,但偶尔我会遇到一个无限循环,这很糟糕(mmm-kay?)。 这是我正在使用的代码:
#!/bin/bash WHITE="\033[0m" GREEN="\033[32m" RED="\033[31m" (run_test_suite 2>&1) | tee out.txt | while IFS=read -r line; do printf "%$(tput cols)s\r" " "; printf "%s\n" "$line"; printf "${WHITE}Passing Tests: ${GREEN}$(grep -c passed out.txt)\t" 2>&1; printf "${WHITE}Failed Tests: ${RED}$( grep -c FAILED out.txt)${WHITE}\r" 2>&1; done
当我遇到这个错误时会发生什么,我会有一个无限重复的错误信息,导致日志文件(
out.txt
)变成一些兆字节的怪物(我认为它进入了GB的一次)。 这是一个重复的示例错误(每组之间有四行空格):warning caused by MY::Custom::Perl::Module::TEST_FUNCTION print() on closed filehandle GEN3663 at /some/CPAN/Perl/Module.pm line 123.
我已经尝试取出
2>&1
重定向,我尝试while IFS=read -r line;
更改while IFS=read -r line;
while read -r line;
,但我一直在无限循环。 更奇怪的是这似乎发生在大多数时间,但有时我完成了长测试套件没有任何问题。编辑 :
我写这篇文章的原因是从黑白测试套件升级到颜色编码的测试套件(因此是ANSI代码)。 以前,我会使用测试套件
run_test_suite > out.txt 2>&1 & watch 'grep -c FAILED out.txt; grep -c passed out.txt; tail -20 out.txt'
以这种方式运行它会从Perl获得相同的警告,但是将其打印到文件并继续运行,而不是陷入无限循环。 使用手表,也打印
[32m
而不是实际将文本渲染为绿色的东西。From some Googling (I'm no bash expert by any means) I was able to put together a bash script that allows me to run a test suite and output a status bar at the bottom while it runs. It typically takes about 10 hours, and the status bar tells me how many tests passed and how many failed.
It works great sometimes, however occasionally I will run into an infinite loop, which is bad (mmm-kay?). Here's the code I'm using:
#!/bin/bash WHITE="\033[0m" GREEN="\033[32m" RED="\033[31m" (run_test_suite 2>&1) | tee out.txt | while IFS=read -r line; do printf "%$(tput cols)s\r" " "; printf "%s\n" "$line"; printf "${WHITE}Passing Tests: ${GREEN}$(grep -c passed out.txt)\t" 2>&1; printf "${WHITE}Failed Tests: ${RED}$( grep -c FAILED out.txt)${WHITE}\r" 2>&1; done
What happens when I encounter the bug is I'll have an error message repeat infinitely, causing the log file (
out.txt
) to become some multi-megabyte monstrosity (I think it got into the GB's once). Here's an example error that repeats (with four lines of whitespace between each set):warning caused by MY::Custom::Perl::Module::TEST_FUNCTION print() on closed filehandle GEN3663 at /some/CPAN/Perl/Module.pm line 123.
I've tried taking out the
2>&1
redirect, and I've tried changingwhile IFS=read -r line;
towhile read -r line;
, but I keep getting the infinite loop. What's stranger is this seems to happen most of the time, but there have been times I finish the long test suite without any problems.EDIT:
The reason I'm writing this is to upgrade from a black & white test suite to a color-coded test suite (hence the ANSI codes). Previously, I would run the test suite using
run_test_suite > out.txt 2>&1 & watch 'grep -c FAILED out.txt; grep -c passed out.txt; tail -20 out.txt'
Running it this way gets the same warning from Perl, but prints it to the file and moves on, rather than getting stuck in an infinite loop. Using watch, also prints stuff like
[32m
rather than actually rendering the text as green.
原文:https://stackoverflow.com/questions/14991148
最满意答案
为了帮助你一点点,你可以在CSS上使用
@media
。这样,您可以在例如屏幕小于特定宽度时更改样式。
HTML:
<div class="wrap"> <div class="image">img</div> <div class="info">info</div> </div>
CSS:
.wrap { background: gray; min-height: 200px; padding: 10px; } .image { width: 270px; height: 180px; background: lightgray; display: inline-block; } .info { background: lightsteelblue; display: inline-block; } @media only screen and (max-width:600px){ .image, .info { width: 100%; display: block; } }
所以风格的作用是当你有一个全屏时它会显示
.image
和.info
彼此相邻(使用display: inline-block;
.image
当屏幕调整大小并且小于600px时,对于这两个div,显示属性将改变block
,使它们出现在彼此之下。参考帖子中的示例,您唯一需要做的就是制作或查找在屏幕变小时调整图像大小的脚本。
希望这对你有所帮助。
To help you a little bit on the way, you could use the
@media
on CSS.With that you can change the style when for example the screen is smaller than a specific width.
HTML:
<div class="wrap"> <div class="image">img</div> <div class="info">info</div> </div>
CSS:
.wrap { background: gray; min-height: 200px; padding: 10px; } .image { width: 270px; height: 180px; background: lightgray; display: inline-block; } .info { background: lightsteelblue; display: inline-block; } @media only screen and (max-width:600px){ .image, .info { width: 100%; display: block; } }
So what the style does is when you have a fullscreen it shows
.image
and.info
next to each other (usingdisplay: inline-block;
. When the screen gets resized and smaller than 600px, for both the divs the display property will change toblock
, making them appear under each other.Referring to the example in your post, the only thing you need to do is to make or find a script that resizes your image when the screen gets smaller.
Hope this helps you.
相关问答
更多-
这有点像你在找什么? http://jsfiddle.net/brsd11/rnwe0mps/ HTML div id='wrap'>我找到了这个问题的答案。 你只需要用下面的CSS来实现一个类。 .truncate{ display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis } I found an answer to this problem. You simply have to implement a class with the following css. .truncate{ display:block; white-space:n ...这是在前端开发中经常发生的问题。 理想情况下,我们应该使用具有完全相同尺寸的图像,以便纵横比保持不变。 当图像有很高的高度时,我们需要以某种方式裁剪图像,使它们具有相同的高度。 这是一个jsFiddle示例,说明您可以做什么。 .image-wrap { overflow: hidden; height: 0; padding-bottom: 50%; } .image-wrap img { max-width: 100%; } 将图像封装在带有overflow: hidden的d ...你很亲密 您只需将此CSS添加到您的li中即可使其工作: width:50%; margin:0; 这些值可以调整。 基本上,我们告诉CSS让元素为ul宽度的50%。 如果你把它设置得更多,它们会换行。 或者,您可以将1设置为40%,将另一个设置为60%,这两个值只需添加到100%(如果添加填充,边距或边框,则更少)。 小提琴 You are close. You just need to add this CSS to your li's to make it work: width:50%; marg ...不确定这是否是您所追求的,但将最小和最大宽度值更改为vw或%,它不会打破框。 DEMO .popbody{ position: absolute; margin: auto; top: 0; left: 0; bottom: 0; right: 0; max-width: 830px; max-height: 450px; width: 100%; } .popboxes{ position: relative; width: 100vw; ...在内部html宽度周围添加一个固定宽度的包装器/容器div。 例如// Your html here.site-container { width:1200px; margin:0 auto; } Add a wrapper/container div around your inner html width a fixed width. e.g.为了帮助你一点点,你可以在CSS上使用@media 。 这样,您可以在例如屏幕小于特定宽度时更改样式。 HTML:imginfo你可以使用flexbox: .child { background-color: #ff0000; height: 20px; width: 100px; max-width: 50%; } #parent { background-color: #00FF00; height: 20px; padding: 20px 0; display: flex; justify-content: space-around; ...
相关文章
更多- bash shell循环的疑问
- bash: scp: command not found的解决方法
- -bash: /bin/mv: Argument list too long的解决方案
- Script.NET Perl解释器代码已经在GitHub开源发布
- 启动script/console时必须在前面加ruby,否则不能启动?
- 安卓版的模拟地理定位器(无限制标点和无限循环)
- shell脚本常规技巧
- mapred streaming 脚本输出运行状态导致的奇怪问题
- Hadoop相关启动脚本分析
- Lua循环遍历
最新问答
更多- python的访问器方法有哪些
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。
- 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
- 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
- NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
元素上的盒子阴影行为(box-shadow behaviour on elements) - Laravel检查是否存在记录(Laravel Checking If a Record Exists)
- 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
- 想学Linux 运维 深圳有哪个培训机构好一点
- 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
- 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
- AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
- 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
- 等待EC2实例重启(Wait for an EC2 instance to reboot)
- 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
- 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
- 江民杀毒软件的KSysnon.sys模块是什么东西?
- 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
- sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
- 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
- AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
- SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
- PerSession与PerCall(PerSession vs. PerCall)
- C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
- 平衡一个精灵(Balancing a sprite)
- n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
- Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
- 湖北京山哪里有修平板计算机的