【发布时间】:2017-10-07 07:56:14
【问题描述】:
我想从 C 程序调用/执行一个 bash,包括在脚本的命令行上传递的任意数量的参数。
我找到了一个相关的帖子How to pass command line arguments from C program to the bash script?,但我的情况是传递给命令行的参数数量可能会有所不同,它不是固定数量。因此 C 程序必须收集任意数量的命令行参数并将其传递给 bash 脚本以执行。
这可能吗?
为了给你一个清晰的概念,当我运行我的测试 bash 脚本时,我得到了预期的输出。
# ./bashex.sh
No arguments passed
# ./bashex.sh hello world
Arguments passed are #1 = hello
Arguments passed are #2 = world
# ./bashex.sh hello world Hi
Arguments passed are #1 = hello
Arguments passed are #2 = world
Arguments passed are #3 = Hi
我不知道如何像这样执行这个脚本,包括来自 C 程序的命令行参数
【问题讨论】:
-
谢谢,我已经有一些 C 程序可以在服务器上执行另一个脚本。问题是收集命令行上传递的任意数量的参数,并将其传递给 C 程序执行的 bash 脚本。
-
@Badda 没有兄弟。如您所见,该线程只有我问题的一部分。该线程仅讨论如何在 Linux 中从 C 执行 shell 脚本。我的问题是执行一个 shell,包括脚本的命令行参数。
-
对不起。这会更像你想要做的吗? *.com/questions/5237482/…
-
为什么这个标签是python?