【问题标题】:How do I run a executable file with command line arguments?如何使用命令行参数运行可执行文件?
【发布时间】:2017-02-28 00:03:21
【问题描述】:

我写了一个 C 文件然后编译它。我必须使用不同的命令行参数运行它并观察结果。我喜欢在 linux 中编写一个 shell 脚本,它使用不同的参数运行我的可执行文件。可以举个例子吗?

【问题讨论】:

    标签: shell command-line-arguments


    【解决方案1】:
    # Assuming your program needed the following arguments,  
    # here is the bash script. Remove the echo to run it.
    args=("-c 1 -d 2 -f a" "-c 2 -d 22 -f b" "-c 6 -d 12 -f z")
    IFS='\n'
    for arg in ${args[@]}
    do
        echo yourexcutable $arg;
    done
    

    【讨论】:

    • 修改IFS 可以防止未引用${args[@]} 的一些问题,但不是全部。这不是一个真正的好方法。
    猜你喜欢
    • 2021-12-21
    • 2019-09-27
    • 2020-09-13
    • 2014-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    相关资源
    最近更新 更多