Sponsored Content
Top Forums Shell Programming and Scripting How to automatically create variables from user input in ksh? Post 302563438 by CarloM on Tuesday 11th of October 2011 08:17:12 AM
Old 10-11-2011
If all you're doing is calculating the average then you don't need each input once it has been processed - just the running total and the number of inputs.

A quick (untested!) example:
Code:
Total=0
Inputs=0
while true
do
   echo -n "Number or q :"
   read UserDecision
   case $UserDecision in
      [0-9]*) Total=`expr $Total + $UserDecision`; : $((Inputs++));;
      *) break;;
   esac
done

Average=`expr $Total / $Inputs`
echo $Inputs $Average

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Expanding Variables in User Input

If have var='$variable' how can I expand $variable. I have tried many thing like duble quotes/braces etc, but nothing worked. I need the solution ASAP. (2 Replies)
Discussion started by: Bsk
2 Replies

2. Shell Programming and Scripting

Create a multi user input form

Hi All, Please ignore if terminology used is incorrect as I am new to Unix. I want to create a Multi user input form which looks something like this: ABCD TOOL Logged User: abcd12 ... (4 Replies)
Discussion started by: vidhu0007
4 Replies

3. Shell Programming and Scripting

every time user input create array perl

Hi, How to create array every time user input and store user input and display all array print " Enter input " my @input = split(' ', $input) chmop($input = <STDIN>; foreach ($input) { @array= @input; } print @array"\n"; (1 Reply)
Discussion started by: guidely
1 Replies

4. Shell Programming and Scripting

no chance to input passwd when create new user in loop

Hi Dears, I have one script to create new users with information in one plain text file. This script will read all lines in the file and create one users for one line. Sample file: #action;login,full name title,expire date,project +;gmwen,Bruce Wen QA,04/01/2012,BT +;xxdeng,Shown Deng... (4 Replies)
Discussion started by: crest.boy
4 Replies

5. Shell Programming and Scripting

create an array which can store the strings from the user input in shell script

I want to create an array which can store the strings from the user input in shell script . example :- I want to store the 5 fruits name in a single array which the user provides . (1 Reply)
Discussion started by: Pkast
1 Replies

6. UNIX for Advanced & Expert Users

Help with ksh script to list, then cp files from a user input date range

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (1 Reply)
Discussion started by: chococrunch6
1 Replies

7. Shell Programming and Scripting

Doing math using user defined input and system environment variables

Hi, I need some help to setup some environmental variables. for example...Get A -> userdefined/user input B -> a number. c -> system variable...for example $GETCONF PAGE_SIZE E = do some math using bc display a message "The value is E" setup the system/kernel paramter sysctl -p... (3 Replies)
Discussion started by: saravanapandi
3 Replies

8. Shell Programming and Scripting

Bash to search file based off user input then create new file

In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file. For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies

9. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

10. Shell Programming and Scripting

Automaticaly create function based off user input

I am trying to create a bash script that will create new function by using the user input. The below will create the necessary files in the correct format, however when it comes to the # create function I am at a loss. If the name entered was NEWNAME and the genes were GENE1,GENE2 then two files... (0 Replies)
Discussion started by: cmccabe
0 Replies
File::RandomAccess(3pm) 				User Contributed Perl Documentation				   File::RandomAccess(3pm)

NAME
File::RandomAccess - Random access reads of sequential file or scalar SYNOPSIS
use File::RandomAccess; $raf = new File::RandomAccess(*FILE, $disableSeekTest); $raf = new File::RandomAccess($data); $err = $raf->Seek($pos); $num = $raf->Read($buff, $bytes); DESCRIPTION
Allows random access to sequential file by buffering the file if necessary. Also allows access to data in memory to be accessed as if it were a file. METHODS
new Creates a new RandomAccess object given a file reference or reference to data in memory. # Read from open file or pipe $raf = new File::RandomAccess(*FILE); # Read from data in memory $raf = new File::RandomAccess($data); Inputs: 0) Reference to RandomAccess object. 1) File reference or scalar reference. 2) flag set if file is already random access (disables automatic SeekTest). Returns: Reference to RandomAccess object. SeekTest Performs test seek() on file to determine if buffering is necessary. If the seek() fails, then the file is buffered to allow random access. SeekTest() is automatically called from new unless specified. $result = $raf->SeekTest(); Inputs: 0) Reference to RandomAccess object. Returns: 1 if seek test passed (ie. no buffering required). Notes: Must be called before any other i/o. Tell Get current position in file $pos = $raf->Tell(); Inputs: 0) Reference to RandomAccess object. Returns: Current position in file Seek Seek to specified position in file. When buffered, this doesn't quite behave like seek() since it returns success even if you seek outside the limits of the file. $success = $raf->Seek($pos, 0); Inputs: 0) Reference to RandomAccess object. 1) Position. 2) Whence (0=from start, 1=from cur pos, 2=from end). Returns: 1 on success, 0 otherwise Read Read data from the file. $num = $raf->Read($buff, 1024); Inputs: 0) Reference to RandomAccess object. 1) Buffer. 2) Number of bytes to read. Returns: Number of bytes actually read. ReadLine Read a line from file (end of line is $/). Inputs: 0) Reference to RandomAccess object. 1) Buffer. Returns: Number of bytes read. Slurp Read whole file into buffer, without changing read pointer. Inputs: 0) Reference to RandomAccess object. Returns: Nothing. BinMode Set binary mode for file. Inputs: 0) Reference to RandomAccess object. Returns: Nothing. Close Close the file and free the buffer. Inputs: 0) Reference to RandomAccess object. Returns: Nothing. AUTHOR
Copyright 2003-2011 Phil Harvey (phil at owl.phy.queensu.ca) This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Image::ExifTool(3pm) perl v5.12.4 2011-01-03 File::RandomAccess(3pm)
All times are GMT -4. The time now is 10:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy