При создании сценария - меню
с диалоговым окном
первым столбцом в меню является тег , который можно выбрать, отображать или нет. Когда меню в порядке, dialog
записывает эти теги в свой вывод (обычно это стандартная ошибка, но помогает опция - stdout
).
Если вы сделаете IP-адрес тегом, вы можете получить адреса непосредственно из запущенного диалогового окна
.
В руководстве эта дополнительная функция описана здесь:
--no-items
Some widgets (checklist, inputmenu, radiolist, menu) display a
list with two columns (a "tag" and "item", i.e., "description").
This option tells dialog to read shorter rows, omitting the
"item" part of the list. This is occasionally useful, e.g., if
the tags provide enough information.
See also --no-tags. If both options are given, this one is ig-
nored.
и
--no-tags
Some widgets (checklist, inputmenu, radiolist, menu) display a
list with two columns (a "tag" and "description"). The tag is
useful for scripting, but may not help the user. The --no-tags
option (from Xdialog) may be used to suppress the column of tags
from the display. Unlike the --no-items option, this does not
affect the data which is read from the script.
Xdialog does not display the tag column for the analogous
buildlist and treeview widgets; dialog does the same.
Normally dialog allows you to quickly move to entries on the
displayed list, by matching a single character to the first
character of the tag. When the --no-tags option is given, dia-
log matches against the first character of the description. In
either case, the matchable character is highlighted.
Вы можете выбрать строки из / etc / hosts
различными способами, например, используя sed
:
sed -e '1,/# ETHERNET SWITCHES/d' -e '/# END SWITCHES/,9999d' /etc/hosts
, и вы можете перенаправить его в свою командную строку в диалог
, поместив его в $ (
и )
.
Комбинируя ярлык 1,2,3 с SW1, SW2, SW3 в описании и используя параметр - no-tags
, вы можете сохранить IP- адрес и описание связаны.
Пример, который вы имеете в виду, может быть примерно таким:
#!/bin/bash
INPUT=/etc/hosts
let i=0 # define counting variable
W=() # define working array
while read -r addr line; do # process file by file
let i=$i+1
W+=($addr "$i $line")
done < <( sed -e '1,/# ETHERNET SWITCHES/d' -e '/# END SWITCHES/,9999d' $INPUT )
FILE=$(dialog --stdout --no-tags --title "List of Switches in /etc/hosts file" --menu "Chose one" 24 80 17 "${W[@]}" ) # show dialog and store output
clear
if [ $? -eq 0 ]; then # Exit with OK
ssh $FILE
fi