Assign a command execution result to a variable under Windows or Linux

1. When the execution result of a command is a single line under Windows, the way to convert it to a variable is as follows:
************************** **********
REM retrieve the hostname =begin=
hostname > hostname.cnd
for /F %%i in (hostname.cnd) do (
set host=%%i
goto done
)
:done
del hostname .cnd
REM retrieve the hostname =end=
************************************
2. Under Linux When the execution result of a command is a single line, the way to convert it to a variable is as follows:
**********************
export host=`hostname`;
** ********************

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326981535&siteId=291194637