Forrest logo
back to the ${result_variable_name}=$(whiptail tool

whiptail:tldr:f70f6

whiptail: Display a multiple-choice menu.
$ ${result_variable_name}=$(whiptail --title "${title}" --menu "${message}" ${height_in_chars} ${width_in_chars} ${menu_display_height} "${value_1}" "${display_text_1}" "${value_n}" "${display_text_n}" ..... 3>&1 1>&2 2>&3)
try on your machine

This command is using the whiptail utility to display a menu to the user and store the selected menu option in a variable called "result_variable_name". Here is a breakdown of each component:

  • ${result_variable_name}: This is the name of the variable where the selected menu option will be stored.
  • =: This is the assignment operator which assigns the output of the whiptail command to the variable.
  • $(whiptail --title "${title}" --menu "${message}" ${height_in_chars} ${width_in_chars} ${menu_display_height} "${value_1}" "${display_text_1}" "${value_n}" "${display_text_n}" ..... 3>&1 1>&2 2>&3): This is the actual whiptail command wrapped in command substitution syntax. The result of the whiptail command (the selected menu option) will be captured and assigned to the variable.

The whiptail options used in this command are as follows:

  • --title "${title}": Sets the title of the menu dialog to the value of the "title" variable.
  • --menu "${message}": Sets the text of the menu prompt to the value of the "message" variable.
  • ${height_in_chars}: Specifies the height of the menu dialog in characters.
  • ${width_in_chars}: Specifies the width of the menu dialog in characters.
  • ${menu_display_height}: Specifies the number of menu items to display at a time.
  • "${value_1}" "${display_text_1}" "${value_n}" "${display_text_n}" .....: Pairs of menu item values and display texts. Each menu option consists of a value (which will be stored in the variable when selected) and a display text (shown to the user in the menu).

Finally, the redirections 3>&1 1>&2 2>&3 are used to swap file descriptors in order to redirect the output of the whiptail command to stderr (file descriptor 2) and redirect stderr to stdout (file descriptor 1). This is usually done to ensure that the menu is displayed correctly in the terminal.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the ${result_variable_name}=$(whiptail tool