关于shell命令的返回值

来源:互联网 发布:中国周边外交战略优化 编辑:程序博客网 时间:2024/06/11 05:01

脚本test.sh     shell编程如下:

  1 #!/bin/bash
  2 echo -e "Hello world! /a /n"
  3 exit 0

 

 

执行:

 

./test.sh     执行后打印:Hello world!

 

echo $?    可以打印它的返回值为:0.

 

 

如果使用system

       #include <stdlib.h>
       int system(const char *command);

 

返回值可以这样使用:

 

 while (something) {
               int ret = system("foo");

               if (WIFSIGNALED(ret) &&
                   (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
                       break;
           }

 

 

原创粉丝点击