Capturing multiple line output into a Bash variable

后端 未结 7 2156
忘掉有多难
忘掉有多难 2020-11-22 03:17

I\'ve got a script \'myscript\' that outputs the following:

abc
def
ghi

in another script, I call:

declare RESULT=$(./myscr         


        
7条回答
  •  自闭症患者
    2020-11-22 03:50

    In case that you're interested in specific lines, use a result-array:

    declare RESULT=($(./myscript))  # (..) = array
    echo "First line: ${RESULT[0]}"
    echo "Second line: ${RESULT[1]}"
    echo "N-th line: ${RESULT[N]}"
    

提交回复
热议问题