Bash Mac OS Expect用于删除配置文件的命令
我们正在替换我们公司使用的配置文件,我们需要运行一个命令来删除旧的配置文件Bash Mac OS Expect用于删除配置文件的命令,bash,macos,expect,Bash,Macos,Expect,我们正在替换我们公司使用的配置文件,我们需要运行一个命令来删除旧的配置文件 /usr/bin/profiles -D 它要求用户输入“您确定要删除所有配置文件吗?[y/n]:” 我们正在尝试自动化这个过程,并且已经研究了expect命令,但是在运行它时遇到了困难 /usr/bin/expect -f - <<EOD spawn /usr/bin/profiles -D expect "Are you sure you want to delete all configurat
/usr/bin/profiles -D
它要求用户输入“您确定要删除所有配置文件吗?[y/n]:”
我们正在尝试自动化这个过程,并且已经研究了expect命令,但是在运行它时遇到了困难
/usr/bin/expect -f - <<EOD
spawn /usr/bin/profiles -D
expect "Are you sure you want to delete all configuration profiles? [y/n]:"
send "y\n"
EOD
谁能帮助我们,我们将非常感激
[…]
是命令替换语法,就像Bash中的$(…)
一样[…]
也特别适用于全局模式(或正则表达式)/usr/bin/expect -f - << 'QUOTED-EOD'
spawn /usr/bin/profiles -D
expect "Are you sure you want to delete all configuration profiles? \\\[y/n]:"
send "y\n"
expect eof; # This is required!
QUOTED-EOD
或者只是
expect {\[y/n]:}
[…]
是命令替换语法,就像Bash中的$(…)
一样[…]
也特别适用于全局模式(或正则表达式)/usr/bin/expect -f - << 'QUOTED-EOD'
spawn /usr/bin/profiles -D
expect "Are you sure you want to delete all configuration profiles? \\\[y/n]:"
send "y\n"
expect eof; # This is required!
QUOTED-EOD
或者只是
expect {\[y/n]:}
首先,这里不需要使用
expect
。您可以只使用以下标志:
-f,自动确认任何问题
i、 e
因为我已经输入了
expect
说明:
方括号作为命令替换进行计算,并且在正则表达式匹配中也需要转义。您可以使用{}
符号来避免这种情况
/usr/bin/expect -f - <<EOD
spawn /usr/bin/profiles -D
expect {Are you sure you want to delete all configuration profiles? \[y/n]:}
send "y\n"
EOD
/usr/bin/expect-f-首先,这里不需要使用expect
。您可以只使用以下标志:
-f,自动确认任何问题
i、 e
因为我已经输入了expect
说明:
方括号作为命令替换进行计算,并且在正则表达式匹配中也需要转义。您可以使用{}
符号来避免这种情况
/usr/bin/expect -f - <<EOD
spawn /usr/bin/profiles -D
expect {Are you sure you want to delete all configuration profiles? \[y/n]:}
send "y\n"
EOD
/usr/bin/expect-f-为什么\r\n
为发送“y\r\n”
?为什么\r\n
为发送“y\r\n”
?