ksh get exit status in assignment

2019-07-23 17:35发布

问题:

I need to know the exit status of command that do assignment.

export VALUE=`My_Get_Value 10`

I need to know the exit status of My_Get_Value script.

In the $? I have the status of assignment itself.

I need it in KSH v93

回答1:

export VALUE=$(My_Get_Value 10) is not an assignment statement; it is a call to the export command, which takes arguments that look like assignment statements. The easiest fix is to separate the assignment from the call to export.

VALUE=$(My_Get_Value 10)
mgv_exit=$?
export VALUE

It doesn't matter if you call export before or after the assignment (as long as you don't call it between the assignment and saving the value of $?), since export sets an attribute on the name VALUE, not the value of the parameter named VALUE. The following is identical:

export VALUE
VALUE=$(My_Get_Value 10)
mgv_exit=$?


标签: shell ksh