UNIX:“wc”的物理位置命令。它不是“/bin”。

发布于 2024-09-27 08:52:10 字数 206 浏览 0 评论 0原文

这已经是树桩了。我用 C 语言编写了一个 shell 程序,允许用户执行多个命令。根据我迄今为止的研究,所有命令(例如“ls”和“cat”)都位于“/bin/”中。

“wc”未在此目录“/bin”中列出。如果我启动终端,我可以输入“wc fileName”并且它可以工作。我从“/”目录运行“find .wc”,仍然找不到“wc”命令。

有谁知道“wc”藏在哪里?

This has be stump. I wrote a shell program in C that allows the user to execute several commands. Based on my research so far, all the commands such as "ls" and "cat" are located in "/bin/".

The "wc" is not listed in this directory - "/bin". If I fire up a terminal, I can type "wc fileName" and it works. I ran "find . wc" from the "/" directory, and I still can't find the "wc" command.

Does anyone know where "wc" is hiding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

满意归宿 2024-10-04 08:52:11

尝试在 shell 中输入 which wc...这应该会告诉您它在哪里。

在我的机器上,它位于 /bin/ 中。

但是,如果您只想自行完成路径解析,则可以使用 system() 函数(有关更多信息,请参阅 man 3 system)。正如您在文档中所读到的,这实际上与调用 Bourne shell(或该符号链接指向的任何地方)进行路径解析相同,因此,如果您不希望产生这种开销,那么您将需要坚持使用任何方法您当前正在使用。

Try typing which wc into your shell...that should tell you where it is.

On my machine it is in /bin/.

However, if you just want the path resolution to be done on it's own, you can use the system() function (see man 3 system for more information). As you can read in the documentation, that's really the same as invoking the Bourne shell (or wherever the symlink for that points to) for the path resolution, so if you don't want that overhead, you will want to stick with whatever method you are currently using.

东京女 2024-10-04 08:52:11

我尝试了 whereis wc 并在 /usr/bin/wc 中找到它

I tried whereis wc and I get it in /usr/bin/wc

晨光如昨 2024-10-04 08:52:11

如果您不想担心各个实用程序在哪里,但确实想避免调用 system 所涉及的开销,那么您应该尝试使用中层函数 execvp,或其朋友之一(也列在该页面上)。遗憾的是,没有 execvpe

If you don't want to worry about where individual utilities are, but you do want to avoid the overhead involved in calling system, then you should try the middle-level function execvp, or one of its friends (also listed on that page). Sadly, there is no execvpe.

那支青花 2024-10-04 08:52:11

您可以尝试使用 whencewhichwhereis 来查找 exec 路径中的任何程序,具体取决于您使用的 shell。

wc 这样的实用程序通常位于 /bin/usr/bin 中,或者像 /usr/local/bin< /code> 或 /usr/site/bin

You can try whence, which, or whereis to find any program in your exec path, depending on which shell you're using.

Utilities like wc are usually located in /binor /usr/bin, or in places like /usr/local/bin or /usr/site/bin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文