gpt4 book ai didi

c - 在 Unix 中如何处理 '<'?

转载 作者:太空宇宙 更新时间:2023-11-04 08:05:15 25 4
gpt4 key购买 nike

我正在测试 argv[]在 C 中,注意到如果你在 shell 中输入类似

./program.out <

' < ' 不是作为参数而是作为其他东西来读取,它给了我一个错误:

bash: syntax error near unexpected token `newline'

谁能解释一下那是什么?

最佳答案

<>是 Bash(和大多数其他 shell)中的许多重定向操作符中的两个。它们通过分别将 stdin 和 stdout 重定向到源或从源重定向来起作用。当你写 a.out < ,您的 shell 需要一个文件名在 < 之后, 是从中读取标准输入的位置。如果不指定任何内容,您的 shell 会遇到尾随的新行并出错。

如果您想将文字“<”传递给您的程序,您需要转义它 - a.out '<' , 或 a.out \< .

进一步阅读:http://www.tldp.org/LDP/abs/html/io-redirection.html

关于c - 在 Unix 中如何处理 '<'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43301354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com