我有需要恢复 Virtualbox 机器的脚本,并且想使用机器名称作为变量,所以我有:
VMN="VMtest"
screen -S MyScr -p 3 -X stuff $'VBoxManage controlvm "${VMN}" resume --type headless\n'
但是变量在此命令中不可见。所以我只在屏幕窗口中看到以下命令
[me@srv ~]$ VBoxManage controlvm resume --type headless
所以我不确定是否需要首先在该屏幕中定义变量或如何将其放在单引号内。
screen 的
stuff
可以理解 \n
,因此您可以在命令中使用双引号:
VMN="VMtest"
screen -S MyScr -p 3 -X stuff "VBoxManage controlvm $VMN resume --type headless\n"
以下方法也适用:
# CTRL-J
... stuff "VBoxManage controlvm $VMN resume --type headless^J"
# \ooo (octal)
... stuff "VBoxManage controlvm $VMN resume --type headless\012"
$' .... '
内部没有发生参数扩展,但您始终可以将这些片段连接成单个字符串:
"VBoxManage controlvm ${VMN} resume --type headless"$'\n'