ksh get exit status in assignment

回眸只為那壹抹淺笑 提交于 2019-12-24 03:37:49

问题


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=$?


来源:https://stackoverflow.com/questions/26784959/ksh-get-exit-status-in-assignment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!