Multiple command output into variable Bash script with $()

后端 未结 2 1995
鱼传尺愫
鱼传尺愫 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:54

    Spaces Not Legal in Variable Assignments

    Variable assignments must not have spaces between the variable name, the assignment operator, and the value. Your current line says:

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

    This actually means "run the following expression with an empty environment variable, where MODEL3 is set but empty."

    What you want is an actual assignment:

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

提交回复
热议问题