help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] how to find only the third command is valid?


From: wk
Subject: [Help-bash] how to find only the third command is valid?
Date: Fri, 5 Feb 2016 18:01:24 +0800

hi,
    my test code is below:
  
 address@hidden test]# cat cmd.c 
#include <stdio.h>
 int main(int argc, char *argv[]) {
        char command[256] = { 0 };
        int ii = 0;
         printf("cmd_len=%d cmd is \n", argc);
        for (ii = 0; ii < argc; ii++) {
                printf("argv[%d]  %s\n", ii, argv[ii]);
        }
        printf("\n");
}
address@hidden test]# gcc -o cmd cmd.c
case 1
address@hidden test]# ./cmd -c "money sho"w
cmd_len=3 cmd is 
argv[0]  ./cmd
argv[1]  -c
argv[2]  money show
  
 case 2
address@hidden test]# ./cmd -c "money "show
cmd_len=3 cmd is 
argv[0]  ./cmd
argv[1]  -c
argv[2]  money show
  
 case 3
address@hidden test]# ./cmd -c "money show"
cmd_len=3 cmd is 
argv[0]  ./cmd
argv[1]  -c
argv[2]  money show

 Question:
 I want to only allow case 3 :
 ./cmd -n admin -p admin -c "money show"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]