<分区>
我想从 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 程序的命令行参数