Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.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
如何使用C在bash中实现逻辑运算符?_C_Bash_Gnu_Logical Operators - Fatal编程技术网

如何使用C在bash中实现逻辑运算符?

如何使用C在bash中实现逻辑运算符?,c,bash,gnu,logical-operators,C,Bash,Gnu,Logical Operators,我是C编程新手。我试图用逻辑运算符编写一个简单的命令行解释器。它的工作原理如下: command1 ; command2 || command3 && command4 if ; second command will be executed after first command if || second command only be executed if first command failed if && second command will only

我是C编程新手。我试图用逻辑运算符编写一个简单的命令行解释器。它的工作原理如下:

command1 ; command2 || command3 && command4
if ; second command will be executed after first command
if || second command only be executed if first command failed
if && second command will only be executed if first one succeeded
例如:

echo one ; echo one || echo two && echo four
输出应如下所示:

command1 ; command2 || command3 && command4
if ; second command will be executed after first command
if || second command only be executed if first command failed
if && second command will only be executed if first one succeeded
一个

一个

任何提示都将不胜感激。

int命令\u执行(无效){
int command_execute(void){
int i;
int next = 0;
int previous = 0;
while(moperator >= 0){ //moperator recorded the numbers of logical operators
    if(execute(words[next], next)== 0){ //words stored the tokenize string 
        moperator--;                    
        for(i = previous; i < nwds; i++){
            if(!strcmp(cwords[i], ";")){ //cwrods is a copy of words  
                previous = i;
                next = i + 1;
                moperator--;
                break;
            }else if(!strcmp(cwords[i], "||")){
                continue;
            }else if(!strcmp(cwords[i], "&&")){
                moperator--;
                previous = i;
                next = i + 1;
                break;
            }
        }
    }else{
        for(i = previous; i < nwds; i++){
            if(!strcmp(cwords[i], ";")){
                previous = i;
                next = i + 1;
                break;
            }else if(!strcmp(cwords[i], "||")){
                previous = i;
                next = i + 1;
                break;
            }else if(!strcmp(cwords[i], "&&")){
                    continue;
                }
        }    
      }
    }
    return 0;
}
int i; int next=0; int-previous=0; 而(moperator>=0){//moperator记录了逻辑运算符的数目 if(execute(words[next],next)==0){//存储在标记化字符串中的单词 摩托车手; 对于(i=先前;i

这是我编写的用来调用以执行命令的方法。输入已通过删除空格进行标记。

显示您迄今为止的尝试。为什么您不能将此添加到您的问题中,而不是将其作为答案?