我如何通过在星号“*”在bash作为参数传递给我的C程序? [英] How do I pass in the asterisk character '*' in bash as arguments to my C program?
本文介绍了我如何通过在星号“*”在bash作为参数传递给我的C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我有一个C程序,并从我的bash运行它:
Let's say I have a C program, and I run it from bash:
$ ./a.out 123 *
$ ./a.out 123 *
该计划将输出所有的命令行参数,
但它会显示这些来代替:
The program would output all the command line arguments, but it will show these instead:
参数1:123
说法二:a.out的
Argument 1: 123 Argument 2: a.out
我可以在我的计划做来解决这个问题?
What can I do in my program to fix this?
推荐答案
外壳与目录中的每个文件的名称替换星号。
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屋!
查看全文