使用'script'命令后如何继续执行脚本



所以我正在编写一个 bash 脚本来创建一些 VM,我需要记录我的命令行的输出,以便在某个时候我尝试使用script命令,但它切断了我的脚本,直到我退出命令, 有没有办法继续执行我的脚本并记录我的命令行?

该脚本如下所示:

script screen.log
for i in 1 2 3
do
onetemplate instantiate "mano"  --user $CUSER --endpoint $CENDPOINT
done
exit

我需要在出口处切断它。

Justscript就会启动一个新的 shell。要让script运行命令,请使用script -c命令。这一切都记录在手册页中。

您可能想尝试:

export CUSER=...
export CENDPOINT=...
script screen.log <<EOF
for i in 1 2 3
do
onetemplate instantiate "mano"  --user $CUSER --endpoint $CENDPOINT
done
EOF

(需要export才能使变量CUSERCENDPOINTscript运行的 shell 中可用。

如果我

使用 -c 选项怎么办,我会怎么做,因为如果我像这样使用它

script -c onetemplate instantiate "mano" --user xxxxxx --endpoint xxxxxx

它说 --用户是无法识别的选项

您必须引用整个命令,例如。

script -c "onetemplate instantiate mano --user xxxxxx --endpoint xxxxxx"

最新更新