简体   繁体   English

将 arguments 从我的 bash 脚本传递到 c 程序

[英]Passing arguments from my bash script into a c program

Im trying to use one of the inputs from my bash script into my c program and i just dont know how to do so.我试图将我的 bash 脚本中的输入之一用于我的 c 程序,我只是不知道该怎么做。 What command should i add for the argument to be passed on to my c program?我应该为要传递给我的 c 程序的参数添加什么命令? Thanx My script is - bash script谢谢我的脚本是 - bash 脚本

I guess that you want to pass the argument to prog.exe and not to gcc , then我猜您想将参数传递给prog.exe而不是gcc ,然后

gcc -c -g -Wall calc_statistics.c gcc -o prog.exe && ./prog.exe "$1"

That is, compile the program and if there are no error run it with the argument.也就是说,编译程序,如果没有错误,则使用参数运行它。

It's not very efficient to compile the program every time the script runs so you can move gcc out.每次脚本运行时都编译程序效率不高,因此您可以将gcc移出。

You can also check your script using shellcheck .您还可以使用shellcheck检查您的脚本。

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

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