Sponsored Content
Top Forums Shell Programming and Scripting Need Help with function that has multiple ranges Post 302521504 by Emin_Em on Wednesday 11th of May 2011 11:01:39 AM
Old 05-11-2011
Need Help with function that has multiple ranges

I have a problem that I cant figure out what to do in this function i need it to count multiple ranges like 0 10, 5 10, 1 100. I know that my counter needs to be outside the function and that it needs to be set to the lowest numbered positional parameter but thats were I am having trouble if anybody can take look at the code and help me out I would appreciate the help.

Here is the code:
Code:
#! /bin/bash 

count_up () 
{
  echo "Couting UP"
  n=0 
  until [[ $n -gt $1 ]]
  do
    printf "$n \n" 
    n=$(( $n + 1 )) 
  done 
}

count_down () 
{
  echo "Couting DOWN"
  n=$1
  while [[ $n -gt 0 ]]
  do
    printf "$n \n" 
    n=$(( $n - 1 )) 
  done 
} 

count_up $1
count_down $1


Last edited by Scott; 05-11-2011 at 06:16 PM.. Reason: Please use code tags and indent code
 

10 More Discussions You Might Find Interesting

1. Programming

returning multiple values from a function in C

hi how can I return multiple values from a C function. I tried the following: #include <stdio.h> void foo(int id, char *first_name, char *last_name) { /* this is just an example to illustrate my problem... real code makes use of the "id" parameter. */ first_name = (char... (8 Replies)
Discussion started by: Andrewkl
8 Replies

2. Shell Programming and Scripting

How to achieve Parellelism for the function which has multiple cp commands

Hi, Here is my requirement. Currently, there is a function which gets called in a for loop 2 times. doCopy() { cp /src/a*.jar /target/ cp /src/b*.jar /target/ cp /src/c*.jar /target } Since it is called sequentially from the for loop, I was asked to make parellel copy to... (7 Replies)
Discussion started by: kgsrinivas
7 Replies

3. Programming

Passing multiple values from a function in C

I know multiple values can be returned from a function in C like this: char **read_file ( char * , unsigned long int * );//this is the function prototypeunsigned long int number_of_words = 0;//variable defined in main() and initialized to 0words_from_dictionary = read_file ( "dictionary.dit" ,... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

4. Shell Programming and Scripting

extracting columns falling within specific ranges for multiple files

Hi, I need to create weekly files from daily records stored in individual monthly filenames from 1999-2010. my sample file structure is like the ones below: daily record stored per month: 199901.xyz, 199902.xyz, 199903.xyz, 199904.xyz ...199912.xyz records inside 199901.xyz (original data... (4 Replies)
Discussion started by: ida1215
4 Replies

5. Shell Programming and Scripting

How to convert multiple number ranges into sequence?

Looking for a simple way to convert ranges to a numerical sequence that would assign the original value of the range to the individual numbers that are on the range. Thank you given data 13196-13199 0 13200 4 13201 10 13202-13207 3 13208-13210 7 desired... (3 Replies)
Discussion started by: jcue25
3 Replies

6. Shell Programming and Scripting

Returning and capturing multiple return values from a function

Hi I am pretty confused in returning and capturing multiple values i have defined a function which should return values "total, difference" i have used as #!/usr/bin/ksh calc() { total=$1+$2 echo "$total" diff=$2-$1 echo "$diff" } I have invoked this function as calc 5 8 Now i... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

7. Shell Programming and Scripting

Using multiple gsub() function under a loop in awk

Hi ALL, I want to replace string occurrence in my file "Config" using a external file named "Mapping" using awk. $cat Config ! Configuration file for RAVI ! Configuration file for RACHANA ! Configuration file for BALLU $cat Mapping ravi:ram rachana:shyam ballu:hameed The... (5 Replies)
Discussion started by: useless79
5 Replies

8. Shell Programming and Scripting

Sum values of specific column in multiple files, considering ranges defined in another file

I have a file (let say file B) like this: File B: A1 3 5 A1 7 9 A2 2 5 A3 1 3 The first column defines a filename and the other two define a range in that specific file. In the same directory, I have also three more files (File A1, A2 and A3). Here is 10 sample lines... (3 Replies)
Discussion started by: Bastami
3 Replies

9. Shell Programming and Scripting

[bash] wanted: function with a clean way for multiple return values

Hi, I have a small part of a project which is done as a bash script. bash was selected as an portability issue that works out of the box. In this script I have an exec shell-function, a wrapper around arbitrary commands. I want to have STDOUT, as an addon STDERR and the EXIT-CODE of a specified... (5 Replies)
Discussion started by: stomp
5 Replies

10. Shell Programming and Scripting

How to call Oracle function with multiple arguments from shell script?

Dear All, I want to know how can i call oracle function from shell script code . My oracle function have around 5 input parameters and one return value. for name in *.csv; do echo "connecting to DB and start processing '$name' file at " echo "csv file name=$x" sqlplus -s scoot/tiger <!... (2 Replies)
Discussion started by: Balraj
2 Replies
MPI_Group_range_incl(3OpenMPI)											    MPI_Group_range_incl(3OpenMPI)

NAME
MPI_Group_range_incl - Creates a new group from ranges of ranks in an existing group. SYNTAX
C Syntax #include <mpi.h> int MPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group *newgroup) Fortran Syntax INCLUDE 'mpif.h' MPI_GROUP_RANGE_INCL(GROUP, N, RANGES, NEWGROUP, IERROR) INTEGER GROUP, N, RANGES(3,*), NEWGROUP, IERROR C++ Syntax #include <mpi.h> Group Group::Range_incl(int n, const int ranges[][3]) const INPUT PARAMETERS
group Group (handle). n Number of triplets in array ranges (integer). ranges A one-dimensional array of integer triplets, of the form (first rank, last rank, stride) indicating ranks in group or processes to be included in newgroup. OUTPUT PARAMETERS
newgroup New group derived from above, in the order defined by ranges (handle). IERROR Fortran only: Error status (integer). DESCRIPTION
If ranges consist of the triplets (first1, last1, stride1), ..., (firstn, lastn, striden) then newgroup consists of the sequence of processes in group with ranks last(1)-first(1) first(1), first(1) + stride(1),..., first(1) + ---------------- stride(1),... stride(1) last(n)-first(n) first(n), first(n) + stride(n),..., first(n) + ---------------- stride(n). stride(n) Each computed rank must be a valid rank in group and all computed ranks must be distinct, or else the program is erroneous. Note that we may have first(i) > last(i), and stride(i) may be negative, but cannot be zero. The functionality of this routine is specified to be equivalent to expanding the array of ranges to an array of the included ranks and passing the resulting array of ranks and other arguments to MPI_Group_incl. A call to MPI_Group_incl is equivalent to a call to MPI_Group_range_incl with each rank i in ranks replaced by the triplet (i,i,1) in the argument ranges. NOTE
This implementation does not currently check to see that the list of ranges to include are valid ranks in the group. ERRORS
Almost all MPI routines return an error value; C routines as the value of the function and Fortran routines in the last argument. C++ func- tions do not return errors. If the default error handler is set to MPI::ERRORS_THROW_EXCEPTIONS, then on error the C++ exception mechanism will be used to throw an MPI:Exception object. Before the error value is returned, the current MPI error handler is called. By default, this error handler aborts the MPI job, except for I/O function errors. The error handler may be changed with MPI_Comm_set_errhandler; the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. Note that MPI does not guarantee that an MPI program can continue past an error. SEE ALSO
MPI_Group_incl MPI_Group_free Open MPI 1.2 September 2006 MPI_Group_range_incl(3OpenMPI)
All times are GMT -4. The time now is 04:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy