Sponsored Content
Full Discussion: Recursion in a bash script
Top Forums UNIX for Dummies Questions & Answers Recursion in a bash script Post 302799037 by bakunin on Thursday 25th of April 2013 04:15:18 PM
Old 04-25-2013
Quote:
Originally Posted by mistsong1
Can you explain this code a little bit? I mainly don't get what the "local FILE" line does
It declares a variable named "FILE" which is local to the function - outside of this function it is not known.

I suggest you consult a man page for bash for keywords you don't know. Usually they are explained there in detail.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

recursion

I'm using the UNIX csh and i wish to use recursion to nav my way up (or down as it is) a given folder. My little test script is called "r" and takes a folder as argv (or $1) #!/bin/tcsh -f set allFiles = `ls -A $argv` cd $argv while ($#allFiles) if (-d... (1 Reply)
Discussion started by: gsjf
1 Replies

2. Shell Programming and Scripting

recursion too deep

I am running a korn shell script which has a recursive function. The script ran for 117 iterations and ended up with the following error "recursion too deep". what should be done to avert this? Thanks in advance Swamy p.s. I am on UNIX MPRAS V4 (3 Replies)
Discussion started by: swamy455
3 Replies

3. Shell Programming and Scripting

Help Help Help in recursion

Hello every body. I am trying to find the factorial using the following code. But it is giving the syntax error. I tried very much but in vain. Thanks in advance for helping me factorial() { if then y=`expr $1 - 1` x=$(( $1 \* factorial $y ))... (6 Replies)
Discussion started by: murtaza
6 Replies

4. Programming

Recursion

I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language. (5 Replies)
Discussion started by: joshighanshyam
5 Replies

5. Shell Programming and Scripting

recursion script problem

Hi Guys,, I tried to create a recursive function in unix. The following is the code. #/bin/sh function(){ n=$1; if ; then out=1; echo "inside if for 0"; else out = `$n * function "$n-1"`; echo "inside if for $n-1; fi (3 Replies)
Discussion started by: mac4rfree
3 Replies

6. Shell Programming and Scripting

Shell script to generate Fibonacci series using recursion

I am facing problem with Shell script to generate Fibonacci series using recursion i.e. recursive function. Here is my script: #!/bin/sh fibo() { no=$1 if ; then return 0 elif ; then return 1 else a1=`expr $no - 1` fibo $a1 ... (10 Replies)
Discussion started by: Tapas Bose
10 Replies

7. Programming

C Recursion (explain)

Hi, Question: how come the output is like that? Can explain to me abit. I am learning C. Thanks! #include <stdio.h> #include <string.h> void printit(char line_of_char, int index); int main() { char line_of_char; int index = -1; strcpy(line_of_char, "This is a string."); ... (5 Replies)
Discussion started by: seede
5 Replies

8. Shell Programming and Scripting

script recursion

Can someone please explain me why the following script calls it self recursively: #!/bin/bash echo Called $0 while this not: #!/bin/bash echo Called $($0) Thanks (6 Replies)
Discussion started by: superpointer
6 Replies

9. Shell Programming and Scripting

Bash variable recursion

Not sure how to ask this question. I want concatenate strings and variable recursively into new variable. For example: infile01=/dir/subfolder/file01.txt infile02=/dir/subfolder/file02.txt infile03=/dir/subfolder/file03.txt for i in {01..03} do u=${"infile"$i} echo $u doneI got error... (7 Replies)
Discussion started by: yifangt
7 Replies

10. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies
explain_ferror(3)					     Library Functions Manual						 explain_ferror(3)

NAME
explain_ferror - explain ferror(3) errors SYNOPSIS
#include <libexplain/ferror.h> const char *explain_ferror(FILE *fp); const char *explain_errno_ferror(int errnum, FILE *fp); void explain_message_ferror(char *message, int message_size, FILE *fp); void explain_message_errno_ferror(char *message, int message_size, int errnum, FILE *fp); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the ferror(3) system call. explain_ferror const char *explain_ferror(FILE *fp); The explain_ferror function is used to obtain an explanation of an error returned by the ferror(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (ferror(fp) < 0) { fprintf(stderr, "%s ", explain_ferror(fp)); exit(EXIT_FAILURE); } It is essential that this function cal be placed as close as possible to the I/O code that has caused the problem, otherwise intervening code could have altered the errno global variable. fp The original fp, exactly as passed to the ferror(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_errno_ferror const char *explain_errno_ferror(int errnum, FILE *fp); The explain_errno_ferror function is used to obtain an explanation of an error returned by the ferror(3) system call. The least the mes- sage will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (ferror(fp) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_ferror(err, fp)); exit(EXIT_FAILURE); } It is essential that this function cal be placed as close as possible to the I/O code that has caused the problem, otherwise intervening code could have altered the errno global variable. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. fp The original fp, exactly as passed to the ferror(3) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_message_ferror void explain_message_ferror(char *message, int message_size, FILE *fp); The explain_message_ferror function may be used to obtain an explanation of an error returned by the ferror(3) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (ferror(fp) < 0) { char message[3000]; explain_message_ferror(message, sizeof(message), fp); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } It is essential that this function cal be placed as close as possible to the I/O code that has caused the problem, otherwise intervening code could have altered the errno global variable. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. fp The original fp, exactly as passed to the ferror(3) system call. explain_message_errno_ferror void explain_message_errno_ferror(char *message, int message_size, int errnum, FILE *fp); The explain_message_errno_ferror function may be used to obtain an explanation of an error returned by the ferror(3) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (ferror(fp) < 0) { int err = errno; char message[3000]; explain_message_errno_ferror(message, sizeof(message), err, fp); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } It is essential that this function cal be placed as close as possible to the I/O code that has caused the problem, otherwise intervening code could have altered the errno global variable. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. fp The original fp, exactly as passed to the ferror(3) system call. SEE ALSO
ferror(3) check stream status explain_ferror_or_die(3) check stream status and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_ferror(3)
All times are GMT -4. The time now is 05:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy