简体   繁体   English

在自定义外壳中标记参数

[英]Tokenize Argument in custom shell

I have quick questions. 我有简单的问题。

I'm creating a basic custom shell, and I have a question regarding token. 我正在创建一个基本的自定义外壳,我对令牌有疑问。 I tokenize the input string from the user into args[i] 我将用户输入的字符串标记为args[i]

My question is: 我的问题是:

$ cd my_file
// means that args[0] is 'cd' and args[1] is 'my_file'

$ ls
// means that args[0] is 'ls' but what is args[1]? Is it NULL or '\0' or what?

what is args[1] in ls? ls中的args[1]是什么? Is it NULL or '\\0' or what? NULL还是'\\0'还是什么?

I'm planning to do a strcmp for the args[i] . 我打算为args[i]做一个strcmp。 thank you 谢谢

You are implementing the tokenization so it is up to you to define that any way you like. 您正在实现令牌化,因此您可以根据自己的喜好定义令牌。 But the standard C argv passed to main has argv[argc] set to NULL if that's what you are asking about. 但是,如果这是您要询问的,则传递给main的标准C argv argv[argc]设置为NULL So, for the standard C main , if the command is ls then argv[0] is "ls" and argv[1] is NULL . 因此,对于标准C main ,如果命令为lsargv[0]"ls"argv[1]NULL – kaylum –贝壳

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM