Multiple command output into variable Bash script with $()

后端 未结 2 2023
鱼传尺愫
鱼传尺愫 2021-01-24 20:25

I reviewed the multiple threads on this and am still having issues, here is the command I\'m trying to execute. Commands without the $() print the desired output t

2条回答
  •  既然无缘
    2021-01-24 20:56

    That is correct:

    MODEL3=$(/usr/sbin/getSystemId | grep "Product Name" | awk '{print $4}')
    

    But you can write the same without grep:

    MODEL3=$(/usr/sbin/getSystemId | awk '/Product Name/{print $4}')
    

    Now you have the result in the MODEL3 variable and you can use it further as $MODEL3:

    echo "$MODEL3"
    

提交回复
热议问题