Sponsored Content
Top Forums Shell Programming and Scripting Bash: Nested functions and including other scripts Post 302228492 by cfajohnson on Sunday 24th of August 2008 07:47:45 PM
Old 08-24-2008
Quote:
Originally Posted by FractalizeR
Hello.

I have the following problem with bash code:

Code:
function fl1_load_modules_and_get_list()

Use the standard syntax to define functions:

Code:
fl1_load_modules_and_get_list()

Quote:
...........

Please post real code so that it can be copied verbatim.
Quote:
Code:
	for module in $FL_MODULES_TO_PROCESS
	do
		source "${FL_MODULE_DIR}/${module}/module.sh"
	done
...........
}

function fl1_handle_install
{
	local FL_MODULES_TO_INSTALL=$(fl1_load_modules_and_get_list $1)
	
	#Executing pre-install routines
	for module in $FL_MODULES_TO_INSTALL
	do
		$(fl_mod_${module}_pre_install)


Do you really want to execute the output of the command?
Quote:
Code:
	done
}

First function is called inside the second one. First function loads scripts in which functions with predefined names reside. The second function calls the first and then attempts to call functions with names, that must be loaded with first one.
Loading files with source seem to complete successfully because I have
Code:
set -o errexit
set -o nounset
set -o pipefail

at the main script.

But when $(fl_mod_${module}_pre_install) call is done, I can see a message like /usr/local/fractal/fl/lib/handle_install.sh: line 8: fl_mod_php_pre_install: command not found
Somehow functions loaded by the first function are not imported into the global scope... Any idea why?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling functions in scripts directly

Hi, I have a menu driven script that does various tasks, I want to be able to call functions directly from within other unix scripts from my menu script. Is this possible? (12 Replies)
Discussion started by: LiquidChild
12 Replies

2. Shell Programming and Scripting

How to call C functions in shell scripts?

How can i call dynamic C functions in shell scripts? (5 Replies)
Discussion started by: agarwal
5 Replies

3. Shell Programming and Scripting

Scripts in ~/bin vs. functions in ~/.bashrc

Hi there, Anyone knows what would be the cons and pros of adding a script in ~/bin vs. a function in ~/.bashrc? I'm not sure how the system keeps tracks of some of the settings loaded in ~/.bashrc (like functions and aliases). Would I be right in thinking that this would all be loaded into... (2 Replies)
Discussion started by: victorbrca
2 Replies

4. Shell Programming and Scripting

nested functions search

I want to write a shell script which traverses a cpp file. Suppose there is function fncn_name6 .. which is called by fncn_name5 which in turn called by fncn_name4 and so on .. in a single cpp class. ie fncn_name1 { fncn_name2 { fncn_name3 } { fncn_name4 ... (0 Replies)
Discussion started by: ultimatix
0 Replies

5. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

6. Shell Programming and Scripting

Nested if question BASH

Just started learning bash ,and I am confused with sintaksis line 16: syntax error near unexpected token `else' thanks #!/bin/bash echo -n "Enter: " read num if(($(echo ${#num}) == 0 )) then echo No arguments passed.Try again elif rem=$(echo $num | tr -d ) ... (7 Replies)
Discussion started by: lio123
7 Replies

7. Shell Programming and Scripting

Nested for loop in bash

Hi, How to use values in one for loop to other for loop. say "$sf_rel" variable has values "2011/W2 2011/G2" I want to use these values in inner for loop to process properly. $branch variable has G2 and 6 What is happening is outer for loop $i has 2011/W2 it is entering into inner... (3 Replies)
Discussion started by: Anjan1
3 Replies

8. AIX

including netsnmp with rc scripts

Hi Admins, I have configured net-snmp with my aix 5.3 server. how to add the same in rc scripts,so that net-snmp will start automatically post server reboot. As per now , i have to start snmp manually after server reboot. Thanks in advance newaix (0 Replies)
Discussion started by: newaix
0 Replies

9. UNIX for Dummies Questions & Answers

Nested loop -bash

I am using the following nested loop for i in {1..3} do for y in {1..3} do if ; then echo P0${i}R${y}.fas mv P0${i}R${y}.fas P${i}R${y}.fas read -t 5 fi done done I was wondering if I can use a character such as * or ? instead of my second variable y. I tried R in... (3 Replies)
Discussion started by: Xterra
3 Replies

10. Shell Programming and Scripting

Call functions from other scripts

i have a file that contains functions and i want the functions to be available in another script. of course, the ideal situation here would be to put the functions in the same script, but i dont own these scripts. so I have to call the functions file from a different script. how do i... (3 Replies)
Discussion started by: SkySmart
3 Replies
All times are GMT -4. The time now is 10:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy