Sponsored Content
Full Discussion: Bash menu item counter
Top Forums Shell Programming and Scripting Bash menu item counter Post 303021264 by annacreek on Tuesday 7th of August 2018 12:32:48 PM
Old 08-07-2018
Bash menu item counter

We have a simple menu with prompt of menu numbers to user.

It is still under construction.

Is there a way to "count" the menu choices so the prompt maximum count can be changed dynamically?



See attached TODO note in code





Code:
read_options(){
        local choice


# the max choice is static 

#TODO add max choice as variable 



        read -p "Enter choice [ 1 - 3] " choice


        case $choice in
                1) one ;;
                2) two ;;
                3) three ;;
                4) select_command_DEBUG "pass command to function" "lsusb"  ;; #pass$
                5) select_command_DEBUG " menu 5 pass list_wlan_interfaces() to func$
                " list_wlan_interfaces " ;;  
                6) pause ;;    # back to GUI exit 0;;
                *) echo -e "${RED}Error...${STD}" && sleep 2
        esac
}

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash menu script

I have a main menu quit=n while do clear echo echo "1. General system information" echo "2. Hardware utilisation information" echo "3. File management" echo "4. User information" echo "5. Information on network connectivity" echo "6. Information on processes" echo "Q.Quit" ... (3 Replies)
Discussion started by: AngelFlesh
3 Replies

2. Shell Programming and Scripting

cant get a counter to work in bash scipt, this is calling expect script

I have looked high and low, tryed lots of diffrent things but cant get a simple counter to work right. what i need is to increase a count ever time it finishes the test, pass or fail. example TEST PASS 1, NEXT TEST PASS 2, I curently have set foo o while {$foo <=5} { incr foo puts... (1 Reply)
Discussion started by: melvin
1 Replies

3. Shell Programming and Scripting

loop with a counter on a constant in bash

Hello Everyone, I'm in need of assistance on creating a script with a counter on a certain string. Basically this script opens a log file and displays certain log data. There are two key words in the log. START and FINISH. In between the START and FINISH is a variable ACTNUMBER. It will... (1 Reply)
Discussion started by: rxc23816
1 Replies

4. Shell Programming and Scripting

get chosen value from bash menu

Hi again :) This is just a sample whiptail menu. Works great, but have been trying to get the chosen value into a variable but failing pretty bad...its ther but unsure how to echo it out when needed #! /bin/bash #This is the menu whiptail --title "Menu example" --menu "Choose an... (9 Replies)
Discussion started by: olearydc
9 Replies

5. Shell Programming and Scripting

Bash shell script undefined array item value question

Hello, I'm new here. I test these expressions's value in my script : (in centOS 6 ) #!/bin/bash array='something' echo "############" echo ${array} echo ${array} echo ${array} echo "############" The output result is : ################# something something #################... (5 Replies)
Discussion started by: lingjing
5 Replies

6. Shell Programming and Scripting

Bash counter increment not working

Hi all, I'm using Bash 4.3.8 on an Ubuntu system, and no matter what I try, incrementing a counter won't work. The simplest example would be something like this: #!/bin/bash myVar=0 myVar=$((myVar++)) echo myVar The variable should be 1, but it's always 0. I've tried every increment... (6 Replies)
Discussion started by: Zel2008
6 Replies

7. Open Source

Bash menu not running

The perl command is not executing? I am trying to run the .pl in my cygwin home directory (C:\cygwin\home\cmccabe) using ${id}.txt.hg19_multianno.txt (located in the annovar directory) as the input file to be formatted and $FILENAME is the output file to be saved. The .pl is attached as... (8 Replies)
Discussion started by: cmccabe
8 Replies

8. Shell Programming and Scripting

How to compare previous and current item in for loop in bash?

Hey, I am trying to compare formated login and logout dates from one user at a host which I have stored in a tmp directory in order to find out the total login time. I need to compare them in order to find overlapping intervals. At first I tried to store each log in and logo date in an array... (3 Replies)
Discussion started by: Mumu123
3 Replies

9. UNIX for Beginners Questions & Answers

Gnome 3.28.3 menu item dissapears under the system menu

I installed CentOS 8 with Gnome 3.28.2 and I noticed that the "switch user" menu item disappeared from under the system menu of Gnome classic (Both X11 & Wayland). I checked google and this problem seems to have a history going back several releases of Gnome. Unfortunately, I never found a... (1 Reply)
Discussion started by: bodisha
1 Replies
ckitem(1)							   User Commands							 ckitem(1)

NAME
ckitem, erritem, helpitem - build a menu; prompt for and return a menu item SYNOPSIS
ckitem [-Q] [-W width] [-uno] [-f filename] [-l label] [ [-i invis] [,...]] [-m max] [-d default] [-h help] [-e error] [-p prompt] [ -k pid [-s signal]] [ choice [...]] /usr/sadm/bin/erritem [-W width] [-e error] [ choice [..]] /usr/sadm/bin/helpitem [-W width] [-h help] [ choice [..]] DESCRIPTION
The ckitem utility builds a menu and prompts the user to choose one item from a menu of items. It then verifies the response. Options for this command define, among other things, a prompt message whose response will be a menu item, text for help and error messages, and a default value (which will be returned if the user responds with a carriage return). By default, the menu is formatted so that each item is prepended by a number and is printed in columns across the terminal. Column length is determined by the longest choice. Items are alphabetized. All messages are limited in length to 70 characters and are formatted automatically. Any white space used in the definition (including new- line) is stripped. The -W option cancels the automatic formatting. When a tilde is placed at the beginning or end of a message definition, the default text will be inserted at that point, allowing both custom text and the default text to be displayed. If the prompt, help or error message is not defined, the default message (as defined under NOTES) will be displayed. Two visual tool modules are linked to the ckitem command. They are erritem (which formats and displays an error message) and helpitem (which formats and displays a help message). These modules should be used in conjunction with FML objects. In this instance, the FML object defines the prompt. When choice is defined in these modules, the messages will describe the available menu choice (or choices). OPTIONS
The following options are supported: -d default Define the default value as default. The default is not validated and so does not have to meet any criteria. -e error Define the error message as error. -f filename Define a file, filename, which contains a list of menu items to be displayed. (The format of this file is: token<tab>description. Lines beginning with a pound sign (#) are designated as comments and ignored.) -h help Define the help messages as help. -i invis Define invisible menu choices (those which will not be printed in the menu). (For example, ``all'' used as an invisible choice would mean it is a legal option but does not appear in the menu. Any number of invisible choices may be defined.) Invisible choices should be made known to a user either in the prompt or in a help message. -k pid Specify that the process ID pid is to be sent a signal if the user chooses to abort. -l label Define a label, label, to print above the menu. -m max Define the maximum number of menu choices that the user can choose. The default is 1. -n Specify that menu items should not be displayed in alphabetical order. -o Specify that only one menu token will be returned. -p prompt Define the prompt message as prompt. -Q Specify that quit will not be allowed as a valid response. -s signal Specify that process ID pid defined with the -k option is to be sent signal signal when quit is chosen. If no signal is specified, SIGTERM is used. -u Specify that menu items should be displayed as an unnumbered list. -W width Specify that prompt, help and error messages will be formatted to a line length of width. OPERANDS
The following operand is supported: choice Define menu items. Items should be separated by white space or newline. EXIT STATUS
The following exit values are returned: 0 Successful execution. 1 EOF on input, or negative width on -W option, or inability to open file on -f option, or usage error. 3 User termination (quit). 4 No choices from which to choose. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) NOTES
The user may input the number of the menu item if choices are numbered or as much of the string required for a unique identification of the item. Long menus are paged with 10 items per page. When menu entries are defined both in a file (by using the -f option) and also on the command line, they are usually combined alphabeti- cally. However, if the -n option is used to suppress alphabetical ordering, then the entries defined in the file are shown first, followed by the options defined on the command line. The default prompt for ckitem is: Enter selection [?,??,q]: One question mark will give a help message and then redisplay the prompt. Two question marks will give a help message and then redisplay the menu label, the menu and the prompt. The default error message if you typed a number is: ERROR: Bad numeric choice specification The default error message if you typed a string is: ERROR: Entry does not match available menu selection. Enter the number of the menu item you wish to select, the token which is associated with the menu item, or a partial string which uniquely identifies the token for the menu item. Enter ?? to reprint the menu. The default help message is: Enter the number of the menu item you wish to select, the token which is associated with the menu item, or a partial string which uniquely identifies the token for the menu item. Enter ? to reprint the menu. When the quit option is chosen (and allowed), q is returned along with the return code 3. SunOS 5.10 14 Sep 1992 ckitem(1)
All times are GMT -4. The time now is 12:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy