Sponsored Content
Top Forums Shell Programming and Scripting help with scripting a simple menu Post 302323243 by vidyadhar85 on Saturday 6th of June 2009 02:22:01 AM
Old 06-06-2009
Are you sure its not homework??SmilieSmilie
hmmm anyways
read <varname>
the <varname> will store whatever entered from Standard I/O
you can use $<varname> where ever you want
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

scripting for menu

Hi, I'm writting a script to filter a cvs log and get only the modified files to move them to a specific directory to compile. I try to filter a line and move from source to target, with no results. Could you help me? for example, in the cvs log file appears: cat log.txt U... (2 Replies)
Discussion started by: Manu
2 Replies

2. Shell Programming and Scripting

Simple Menu and coding

I am very new to Unix and don't know much about it. I've been trying to create a menu and what I don't understand is how to execute a command once a user makes a selection. I have the menu set up. In fact, the following is the code that I have thus far: #! /bin/csh # This is the UNIX menu... (0 Replies)
Discussion started by: sinjin
0 Replies

3. Shell Programming and Scripting

Scripting problem - when the file is not found i want it to return to the menu

when the file is not found i want it to return to the menu, however it carries out the next line when i hit a key I know its probably something simple can anyone help? here is my pause function: function pause(){ read -s -n 1 -p "Press any key to return to Menu . . ." echo } SCRIPT... (2 Replies)
Discussion started by: Alendrin
2 Replies

4. UNIX for Dummies Questions & Answers

Scripting menu problem

Hi there, I am new to Unix and at the moment I am trying to solve my assignment that is to create a script for the program to prompt user to type three codes, from user point of view it should be done by typing codes separating them by spaces. Then program displays a menu with these three... (5 Replies)
Discussion started by: Dannel
5 Replies

5. Shell Programming and Scripting

Perl simple text menu with options

Hopefully I'm in the right place. Im new to the forums and linux! I'm looking to add a menu to my perl hangman game i have created. The menu will use user input for the desired option and then perform the operation indicated. I would like something along the lines of: Welcome to Hangman... (1 Reply)
Discussion started by: jahburmski
1 Replies

6. Shell Programming and Scripting

Two columns output in simple case menu?

EDIT : System used : Any Linux distribution. Hello everyone, I m having quite a headache trying to figure out why I m having a 2 columns output in the following code : #!/bin/ksh menu_rotation() { #Variables CHOIX1="Rotation 1" CHOIX2="Rotation 2" CHOIX3="Rotation 3" ... (11 Replies)
Discussion started by: Sekullos
11 Replies

7. UNIX for Dummies Questions & Answers

Simple bash script menu

Dear Sir, May I know how do I go about adding the following feature into the script below: When user enter values other than 1,2,3,4, a) Message “Wrong entry !!! Pls select 1,2,3 or 4” is displayed b) The screen is cleared again and the menu is displayed. #!/bin/bash clear var=1... (2 Replies)
Discussion started by: fusetrips
2 Replies

8. Shell Programming and Scripting

Simple calculator with menu input - Need Help

I am trying to make a calculator. The user Enters number 1, chooses and operation, enters number 2, then chooses another operation or for the answer to be displayed. eg. 1 + 1 = or 1 + 1 + 2 + 1 = Both of these should be possible. #!/bin/bash read -p "what's the first number? " n1... (3 Replies)
Discussion started by: redshine6
3 Replies

9. Homework & Coursework Questions

Shell scripting/menu

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a shell menu program that will: a. copy a file to a designated directory b. tell you if a specified user... (13 Replies)
Discussion started by: Jagst3r21
13 Replies

10. Shell Programming and Scripting

Menu and case statement scripting

hi all i am trying to get help with writing a script using case statement to display menu as 1) Authentication log 2) System log 3) Messages 4) Dmesg 5) Boot log Q) Exit When selecting the menu by 1 or 2 or 3 o 4 or 5, it should display the last 10 lines of the log files, if... (3 Replies)
Discussion started by: renegade11
3 Replies
hsearch(3C)						   Standard C Library Functions 					       hsearch(3C)

NAME
hsearch, hcreate, hdestroy - manage hash search tables SYNOPSIS
#include <search.h> ENTRY *hsearch(ENTRY item, ACTION action); int hcreate(size_t mekments); void hdestroy(void); DESCRIPTION
The hsearch() function is a hash-table search routine generalized from Knuth (6.4) Algorithm D. It returns a pointer into a hash table indicating the location at which an entry can be found. The comparison function used by hsearch() is strcmp() (see string(3C)). The item argument is a structure of type ENTRY (defined in the <search.h> header) containing two pointers: item.key points to the comparison key, and item.data points to any other data to be associated with that key. (Pointers to types other than void should be cast to pointer-to- void.) The action argument is a member of an enumeration type ACTION (defined in <search.h>) indicating the disposition of the entry if it cannot be found in the table. ENTER indicates that the item should be inserted in the table at an appropriate point. Given a duplicate of an existing item, the new item is not entered and hsearch() returns a pointer to the existing item. FIND indicates that no entry should be made. Unsuccessful resolution is indicated by the return of a null pointer. The hcreate() function allocates sufficient space for the table, and must be called before hsearch() is used. The nel argument is an esti- mate of the maximum number of entries that the table will contain. This number may be adjusted upward by the algorithm in order to obtain certain mathematically favorable circumstances. The hdestroy() function destroys the search table, and may be followed by another call to hcreate(). RETURN VALUES
The hsearch() function returns a null pointer if either the action is FIND and the item could not be found or the action is ENTER and the table is full. The hcreate() function returns 0 if it cannot allocate sufficient space for the table. USAGE
The hsearch() and hcreate() functions use malloc(3C) to allocate space. Only one hash search table may be active at any given time. EXAMPLES
Example 1: Example to read in strings. The following example will read in strings followed by two numbers and store them in a hash table, discarding duplicates. It will then read in strings and find the matching entry in the hash table and print it. #include <stdio.h> #include <search.h> #include <string.h> #include <stdlib.h> struct info { /* this is the info stored in table */ int age, room; /* other than the key */ }; #define NUM_EMPL 5000 /* # of elements in search table */ main( ) { /* space to store strings */ char string_space[NUM_EMPL*20]; /* space to store employee info */ struct info info_space[NUM_EMPL]; /* next avail space in string_space */ char *str_ptr = string_space; /* next avail space in info_space */ struct info *info_ptr = info_space; ENTRY item, *found_item; /* name to look for in table */ char name_to_find[30]; int i = 0; /* create table */ (void) hcreate(NUM_EMPL); while (scanf("%s%d%d", str_ptr, &info_ptr->age, &info_ptr->room) != EOF && i++ < NUM_EMPL) { /* put info in structure, and structure in item */ item.key = str_ptr; item.data = (void *)info_ptr; str_ptr += strlen(str_ptr) + 1; info_ptr++; /* put item into table */ (void) hsearch(item, ENTER); } /* access table */ item.key = name_to_find; while (scanf("%s", item.key) != EOF) { if ((found_item = hsearch(item, FIND)) != NULL) { /* if item is in the table */ (void)printf("found %s, age = %d, room = %d ", found_item->key, ((struct info *)found_item->data)->age, ((struct info *)found_item->data)->room); } else { (void)printf("no such employee %s ", name_to_find) } } return 0; } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
bsearch(3C), lsearch(3C), malloc(3C), string(3C), tsearch(3C), malloc(3MALLOC), attributes(5), standards(5) The Art of Computer Programming, Volume 3, Sorting and Searching by Donald E. Knuth, published by Addison-Wesley Publishing Company, 1973. SunOS 5.10 29 Dec 1996 hsearch(3C)
All times are GMT -4. The time now is 04:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy