使用' echo'补丁命令失败

时间:2018-02-21 17:37:04

标签: linux echo patch

我正在尝试在脚本中嵌入补丁。当我这样做时:

x=$(diff x y)
echo $x | patch x

它有效。但是,当我将差异嵌入脚本中的回声中时,它无法正常工作。以下是我正在使用的准确代码:

echo '
75c75
<           print_stacktrace();
---
> //            print_stacktrace();
93c93,134
< int main(int argc, char **argv) {
---
> int main(int argc, char *argv[]) {
>     if (argc > 1 ) {
>         if ( strcmp(argv[1], "--list") == 0 ) {
>             CxxTest::TestRunner::listTests();
> 
>         } else {
>             struct sigaction act;
>             memset(&act, 0, sizeof(act));
>             act.sa_handler = sig_handler;
>             sigaction(SIGHUP, &act, 0);
>             sigaction(SIGQUIT, &act, 0);
>             sigaction(SIGILL, &act, 0);
>             sigaction(SIGABRT, &act, 0);
>             sigaction(SIGFPE, &act, 0);
>             sigaction(SIGKILL, &act, 0);
>             sigaction(SIGSEGV, &act, 0);
>             sigaction(SIGPIPE, &act, 0);
>             sigaction(SIGALRM, &act, 0);
>             sigaction(SIGTERM, &act, 0);
>             signal(SIGWINCH, SIG_IGN);
> 
>         //--- Skip program name
>             argv++;
> 
>         //--- Note if we can fork() tests
>             if ( *argv != 0  &&  strcmp(*argv, "--fork") == 0 ) {
>                 fork_tests = true;
>                 argv++;
>             }
> 
>             ArthurFixture fixture(*argv++);
> 
>         //--- Collect modules to test. If none, test all.
>             std::set<const char*> args;
>             while ( *argv != 0 ) {
>                 args.insert(*argv);
>                 argv++;
>             }
> 
>         //--- Run tests.
>             return CxxTest::ErrorPrinter().run(args);
>         }
95,124c136
<   if (argc > 1) {
<       if ( strcmp(argv[1], "list") == 0 ) {
<           CxxTest::TestRunner::listTests();
< 
<       } else {
<           struct sigaction act;
<           memset(&act, 0, sizeof(act));
<           act.sa_handler = sig_handler;
<           sigaction(SIGHUP, &act, 0);
<           sigaction(SIGQUIT, &act, 0);
<           sigaction(SIGILL, &act, 0);
<           sigaction(SIGABRT, &act, 0);
<           sigaction(SIGFPE, &act, 0);
<           sigaction(SIGKILL, &act, 0);
<           sigaction(SIGSEGV, &act, 0);
<           sigaction(SIGPIPE, &act, 0);
<           sigaction(SIGALRM, &act, 0);
<           sigaction(SIGTERM, &act, 0);
<           signal(SIGWINCH, SIG_IGN);
< 
<           argv++, argc--;
<           ArthurFixture fixture(*argv);
<           std::set<const char*> args;
< 
<           for ( int i = 1; i < argc; i++ ) {
<               args.insert(argv[i]);
<           }
<           return CxxTest::ErrorPrinter().run(args);
<       }
<   } else {
---
>     } else {
' | patch acceptanceTests/test-root.cpp.normal

每个大块都失败了。我没有将差异放在单独的文件中的原因是脚本可能在文件系统中的任何位置。我试图回应&#39;差异到文件,但这也不起作用。

0 个答案:

没有答案