-1

I make a shell that takes arguments in a command line with special conditions on what it is able to do.

For example, anything that appears after the # character will be considered as a comment and the rest of the command line is rendered negligible.

Such as in the command ls -lR /, you would execute the program /bin/ls (performed using execvp) passing into it the parameters -lR and /.

But in the command ls # -lR /, only /bin/ls will run.

I have already made the parsing function that will tokenize command line into strings of separate arguments so I figured it would start from there.

However, I'm not sure how I would go about commenting out everything else after the # character in the CLI. I am using C++.

1

Only send parts of the line that occur before the ‘#’ to your tokenenize.

  • So how do i do that? Do I have to modify the tokenize function? I'm using strtok() for C++ – Code4life May 11 at 2:25
  • First call strtok using “#” as your token, take only the first item returned from that, and now call strtok again, using your whitespace token. – Don Simon May 14 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.