Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash:将包含程序输出的变量回送到文件_Bash_Grep_Echo_Unison - Fatal编程技术网

Bash:将包含程序输出的变量回送到文件

Bash:将包含程序输出的变量回送到文件,bash,grep,echo,unison,Bash,Grep,Echo,Unison,当我在bash提示符下执行unison tours 2>/dev/null | grep-A 2''时,我得到了我想要的确切输出: *changed <-?-> changed Future Tours/File Clash Test.docx local : changed file modified on 2013-06-05 at 16:24:40 size 10221 rw-rw---- bj-server... : cha

当我在bash提示符下执行unison tours 2>/dev/null | grep-A 2''时,我得到了我想要的确切输出:

*changed  <-?-> changed    Future Tours/File Clash Test.docx  
local        : changed file       modified on 2013-06-05 at 16:24:40  size 10221     rw-rw----  
bj-server... : changed file       modified on 2013-06-05 at 16:23:53  size 10232     rw-rw----*
*已更改未来巡演/文件Clash Test.docx
本地:更改文件于2013-06-05 16:24:40修改大小10221 rw rw-rw--
bj服务器…:更改文件于2013-06-05 16:23:53修改尺寸10232 rw rw----*
当我将其放入shell脚本时:

#!/bin/bash
tmp=$(unison tours 2> /dev/null | grep -A 2 '<-?->')
echo "$tmp" > /home/users/itsystem/test.log
#/bin/bash
tmp=$(unison tours 2>/dev/null | grep-A 2'')
echo“$tmp”>/home/users/itsystem/test.log
。。。结果很奇怪。运行更多test.log,我得到以下结果:

- Systems Sheets/Feedback She oup).xls | Past Tours/2012/CE0 12 Cherry (N...our Menus/Lijiang Tour Menus.xls - Past Tours/2012/UC041112 St - Past Tours/2012/UC081112 Lopata (N... Menus - UC081012 Lo 2/VC110912 Levin (VI... Menus - VC110912 Levin (VI).xlsx xlsx | Future Tours/2013 Futur / Inquiries/Outstanding/Terence Park... Itinerary (Trev changed changed Future Tours/File Clash Test.docx local : changed file modified on 2013-06-05 at 16:24:40 size 10221 rw-rw---- bj-server... : changed file modified on 2013-06-05 at 16:23:53 size 10232 rw-rw---- -系统表/反馈She oup).xls |过去的旅行/2012/CE0 12樱桃(N…我们的菜单/丽江旅游菜单.xls) -过去的旅行/2012/UC041112街 -过去之旅/2012/UC081112 Lopata(N…菜单-UC081012 Lo 2/VC110912列文(VI)菜单-VC110912列文(VI).xlsx xlsx |未来之旅/2013未来 /查询/未完成/特伦斯公园……行程(Trev) 已更改未来巡更/文件Clash Test.docx 本地:更改文件于2013-06-05 16:24:40修改尺寸10221 rw rw---- bj服务器…:更改文件于2013-06-05 16:23:53修改大小10232 rw rw---- 其他的垃圾是从哪里来的

如果您只是运行unison,则会得到一行动画输出,该输出会不断刷新,并显示工作文件夹,但最终会消失


如果我的grep在bash提示符下工作,为什么不使用shell脚本?

动画行包含一系列控制字符,这些字符修改了终端上的光标位置。当输出指向文件时,不会达到相同的效果;您只会得到写入终端的所有字节的记录。

谢谢@chep耐尔-这就解释了额外的输出,谢谢,尽管给出了我的grep子句…为什么它仍然在文件的输出中结束?如果不知道旋转进度指示器是如何产生的,很难对您在日志文件中看到的内容给出确切的解释。但是它看起来像一些(但不是全部)行中包含足够多的微调器,使
grep
与之匹配……问题是我应该匹配“”,这在任何带有微调器的行中都不会出现,因此我感到困惑。请查看带有
hextump
的日志文件。控制光标定位的非打印字符应该是明显的,并且您可以精确地列出输出的内容,这不一定是使用
more
可以看到的内容。