How to return the output of program in a variable?

后端 未结 4 387
轮回少年
轮回少年 2021-01-03 05:14

Can any one tell me how to return the output of a program in a variable from command line?

var = ./a.out params

I am trying to get the outp

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-03 06:09

    For output from multi-line command, you can do this:

    output=$(
    #multiline multiple commands
    )
    

    Or:

    output=$(bash <

    Example:

    #!/bin/bash
    output="$(
    ./a.out params1
    ./a.out params2
    echo etc..
    )"
    echo "$output"
    

提交回复
热议问题