我已经为新用户创建了一个循环来完成一些虚拟机设置功能,这些功能包括添加主机名,IP地址等等。但是,如果我点击任何一个内的“取消”按钮鞭尾窗,它只是移动到循环中的下一个whiptail元素。如果选择Cancel
,如何将其设置为取消循环并返回主菜单窗口?
while true
do
OPTION=$(whiptail --title "Configuration Menu" --menu "Choose an option" 20 78 10 \
"1" "Show current configuration." \
"2" "Setup Wizard." \
...
"0" "EXIT" 3>&1 1>&2 2>&3)
exitstatus=$?
case "$OPTION" in
...
2)
# Setup hostname
HOSTNAME=$(whiptail --inputbox "Hostname" 8 78 `hostname` --title "Serial Number" 3>&1 1>&2 2>&3)
...
# IP address configuration
IP_CONFIG=$(whiptail --title "Network Configuration" --radiolist "Choose a configuration option" 20 78 10 \
"DHCP" "Use Dynamic Host Protocol" ON \
"STATIC" "Configure Static IP" OFF 3>&1 1>&2 2>&3)
...
;;
esac
答案 0 :(得分:1)
好的,想通了。我必须将每个案例选项包装在其自己的exitstatus = 0
测试中:
2)
# Setup serial number
SERIAL=$(whiptail --inputbox "Serial Number" 8 78 `hostname` --title "Serial Number" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
...
else
break
fi
;;
...
答案 1 :(得分:0)
使用退出循环的# Let's begin by importing some libraries we'll need
import numpy as np
from __future__ import print_function # So that this notebook becomes both Python 2 and Python 3 compatible
# And creating some random data
size = 10
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(size) * 100.0)
from bqplot import pyplot as plt
# Creating a new Figure and setting it's title
plt.figure(title='My Second Chart')
# Let's assign the scatter plot to a variable
scatter_plot = plt.scatter(x_data, y_data)
# Let's show the plot
plt.show()
# then enable modification and attach a callback function:
def foo(change):
print('This is a trait change. Foo was called by the fact that we moved the Scatter')
print('In fact, the Scatter plot sent us all the new data: ')
print('To access the data, try modifying the function and printing the data variable')
global pdata
pdata = [scatter_plot.x,scatter_plot.y]
# First, we hook up our function `foo` to the colors attribute (or Trait) of the scatter plot
scatter_plot.observe(foo, ['y','x'])
scatter_plot.enable_move = True
。 break
在whiptail
选择中返回1,因此请对此进行测试,如果是<Cancel>
则为{<1}}:
break