如何将 bash 中的星号字符“*"作为参数传递给我的 C 程序? [英] How do I pass in the asterisk character '*' in bash as arguments to my C program?

查看:26
本文介绍了如何将 bash 中的星号字符“*"作为参数传递给我的 C 程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个 C 程序,我从 bash 运行它:

Let's say I have a C program, and I run it from bash:

$ ./a.out 123 *

程序将输出所有命令行参数,但它会显示这些:

The program would output all the command line arguments, but it will show these instead:

Argument 1: 123
Argument 2: a.out

我可以在我的程序中做些什么来解决这个问题?

What can I do in my program to fix this?

推荐答案

shell 正在将星号替换为目录中每个文件的名称.

The shell is replacing the asterisk with the name of each file in the directory.

要传递文字星号,您应该能够将其转义:

To pass a literal asterisk, you should be able to escape it:

$ ./a.out 123 *

这篇关于如何将 bash 中的星号字符“*"作为参数传递给我的 C 程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆