Sponsored Content
Top Forums UNIX for Dummies Questions & Answers help with extremely basic problem Post 302189471 by tragic54 on Saturday 26th of April 2008 01:26:46 AM
Old 04-26-2008
help with extremely basic problem

Alright i'm having problems with this loop. Basically once the script is ran a parameter is required. Once entering the parameter it displays that in LIMIT. Alright so now the problem, I need my loop to ask my user for a number, and if that number is less than the limit then sum the input values until it reaches the limit.

example output of what i need

LIMIT = 50
please enter a number: 10
I = 10 SUM = 10
please enter a number: 15
I = 15 SUM = 25
please enter a number: 20
I = 20 SUM = 40
please enter a number: 15
done!

this is the code i have so far, the SUM PART is messed up and i dont know how to exit the loop and display done once it reached the limit.

Code:
#!/bin/sh

if [ $# -ne 1 ]; then
    echo "usage: help.sh LIMIT"
exit
fi

LIMIT=$1

echo "LIMIT =" $LIMIT

read -p"Please enter a number: " I

echo "I =" $I "SUM =" $I

while [ $I -le $LIMIT ]
do

read -p"Please enter a number: " X

echo "I =" $X "SUM =" `expr $I + $X`

done

 

8 More Discussions You Might Find Interesting

1. Programming

Basic multi module problem

I am trying to learn how to use multiple modules and hearder files. I have tried a little experiment but cannot get it to work. Here is my code and compilation attempt. Any help with finding my problems appreciated. The main function (main01.c) calls a function located in another file... (9 Replies)
Discussion started by: enuenu
9 Replies

2. Shell Programming and Scripting

Basic Scipting problem need help for school

How to make this script? 1. Write a portable bash shell script called change_password.bash that will prompt the user for a password. Use a series of if statements to test if: 1. The password is NOT 6 or more characters 2. The password does not contain at least 3 consecutive letters... (1 Reply)
Discussion started by: 3junior
1 Replies

3. Shell Programming and Scripting

Basic problem

Hello Friends, I am learning Perl now. I have a small query. I have a directory Z with file name Z.txt. I would like to copy this file Z.txt to 3 new dir with new filenames as follows dir 1 1.txt dir 2 2.txt dir 3 3.txt I would like to then open 1.txt from dir 1 and edit the first... (0 Replies)
Discussion started by: ramesh54
0 Replies

4. UNIX for Dummies Questions & Answers

Basic number checking problem

Hello all I am having problems using a bash script to read the input from the user and checking that its a valid number. I only want the user to input a maximum of a 3 number string (321 , 521 , 871 etc.). Anything longer or that includes a chararcter or symbol will display an error message. ... (8 Replies)
Discussion started by: ChrisHoogie
8 Replies

5. Shell Programming and Scripting

Expr problem and other basic problems

Hello, I am new to the Bash scripting language, and was given a tutorial page on how to setup a file. However I am trying to use cygwin to run this file and it is not working. $ vi averagetime.sh # # # echo "Enter Dictorinary File Text " read dict echo "Enter Grid Name" read grid... (13 Replies)
Discussion started by: killerqb
13 Replies

6. UNIX for Dummies Questions & Answers

Basic if statement problem

I am using the following code: if ; then I am getting an error saying line 12: The code is supposed to examine whether the filename read into $FILE includes the string IMG*. I do have a fi later in the script, but I must be missing something obvious. Can anyone help? (3 Replies)
Discussion started by: Bengel
3 Replies

7. UNIX for Dummies Questions & Answers

Basic problem with pdftotext

Hi, I have used pdftotext with good results in the past, but today for some reason I keep getting the same error message. My command is as follows: And the error message is I am using Vmware player with Ubuntu server, but I don't think that is causing this issue as I have been using... (2 Replies)
Discussion started by: Joq
2 Replies

8. UNIX for Dummies Questions & Answers

Very basic problem with fork() using c

Hi guys, I have the following code: int main(int argc, char *argv) { int pid1,pid2,i=0; pid1=fork(); i+=2; if(!pid1) i++; if(i%3) pid2=fork(); if (pid2==0) { printf("sea \n "); i-=1; } if(i>=2)... (4 Replies)
Discussion started by: pfpietro
4 Replies
ILAENV(l)								 )								 ILAENV(l)

NAME
ILAENV - i called from the LAPACK routines to choose problem-dependent parameters for the local environment SYNOPSIS
INTEGER FUNCTION ILAENV( ISPEC, NAME, OPTS, N1, N2, N3, N4 ) CHARACTER*( * ) NAME, OPTS INTEGER ISPEC, N1, N2, N3, N4 PURPOSE
ILAENV is called from the LAPACK routines to choose problem-dependent parameters for the local environment. See ISPEC for a description of the parameters. This version provides a set of parameters which should give good, but not optimal, performance on many of the currently available comput- ers. Users are encouraged to modify this subroutine to set the tuning parameters for their particular machine using the option and problem size information in the arguments. This routine will not function correctly if it is converted to all lower case. Converting it to all upper case is allowed. ARGUMENTS
ISPEC (input) INTEGER Specifies the parameter to be returned as the value of ILAENV. = 1: the optimal blocksize; if this value is 1, an unblocked algo- rithm will give the best performance. = 2: the minimum block size for which the block routine should be used; if the usable block size is less than this value, an unblocked routine should be used. = 3: the crossover point (in a block routine, for N less than this value, an unblocked routine should be used) = 4: the number of shifts, used in the nonsymmetric eigenvalue routines = 5: the minimum column dimension for blocking to be used; rectangular blocks must have dimension at least k by m, where k is given by ILAENV(2,...) and m by ILAENV(5,...) = 6: the crossover point for the SVD (when reducing an m by n matrix to bidiagonal form, if max(m,n)/min(m,n) exceeds this value, a QR factorization is used first to reduce the matrix to a triangular form.) = 7: the number of processors = 8: the crossover point for the multishift QR and QZ methods for nonsymmetric eigenvalue problems. = 9: maximum size of the sub- problems at the bottom of the computation tree in the divide-and-conquer algorithm (used by xGELSD and xGESDD) =10: ieee NaN arith- metic can be trusted not to trap =11: infinity arithmetic can be trusted not to trap NAME (input) CHARACTER*(*) The name of the calling subroutine, in either upper case or lower case. OPTS (input) CHARACTER*(*) The character options to the subroutine NAME, concatenated into a single character string. For example, UPLO = 'U', TRANS = 'T', and DIAG = 'N' for a triangular routine would be specified as OPTS = 'UTN'. N1 (input) INTEGER N2 (input) INTEGER N3 (input) INTEGER N4 (input) INTEGER Problem dimensions for the subroutine NAME; these may not all be required. >= 0: the value of the parameter specified by ISPEC < 0: if ILAENV = -k, the k-th argument had an illegal value. FURTHER DETAILS
The following conventions have been used when calling ILAENV from the LAPACK routines: 1) OPTS is a concatenation of all of the character options to subroutine NAME, in the same order that they appear in the argument list for NAME, even if they are not used in determining the value of the parameter specified by ISPEC. 2) The problem dimensions N1, N2, N3, N4 are specified in the order that they appear in the argument list for NAME. N1 is used first, N2 second, and so on, and unused problem dimensions are passed a value of -1. 3) The parameter value returned by ILAENV is checked for validity in the calling subroutine. For example, ILAENV is used to retrieve the optimal blocksize for STRTRI as follows: NB = ILAENV( 1, 'STRTRI', UPLO // DIAG, N, -1, -1, -1 ) IF( NB.LE.1 ) NB = MAX( 1, N ) LAPACK version 3.0 15 June 2000 ILAENV(l)
All times are GMT -4. The time now is 07:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy