ksh get exit status in assignment

2019-07-23 17:27发布

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

标签: shell ksh
1条回答
别忘想泡老子
2楼-- · 2019-07-23 17:46

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=$?
查看更多
登录 后发表回答