Bash: Nested functions and including other scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash: Nested functions and including other scripts
# 8  
Old 08-25-2008
Quote:
Originally Posted by FractalizeR
Thank you for valuable comments!

Sorry, I meant
./f-linsey.sh install all
Of course, it wouldn't start without .sh.

Details like that can cause a script to fail.
Quote:

Line, which causes error is
Code:
fl_mod_${module}_install

in lib/handle_install.sh

It just says, that command not found. But specific module /modules/httpd/module.sh should be loaded to that moment.
Should be???? Didn't you check?

Add a line to the file containing it to confirm that it is indeed loaded:
Code:
echo modules/httpd/module.sh
function fl_mod_httpd_order()
{
        echo "001000"
}

Or put set -x in the script to turn on debugging.
Quote:

I am not yet familiar with Linux

It has nothing to do with Linux; POSIX shell scripting is common to all *nix variants (and some other systems).
Quote:
and this style of code seem to come from PHP Smilie

It is nothing like PHP.


Some further comments:

Some of the files are missing a final newline. (It will probably not make a difference, but it should be there.)

You use a mixture of syntaxes for defining functions (POSIX, KSH and a combination of the two that is only valid in bash). Stick to the POSIX standard form:
Code:
function_name() COMPOUND_COMMAND

Where do you call the function fl1_load_modules_and_get_list?

Last edited by cfajohnson; 08-25-2008 at 08:46 PM..
# 9  
Old 08-26-2008
Quote:
Should be???? Didn't you check?
fl1_load_modules_and_get_list() is called from lib/handle_install.sh
For each module there source is included by
Code:
source "${FL_MODULE_DIR}/${module}/module.sh"

Later for each module
Code:
fl_mod_${module}_pre_install

is called, which in turn fails...
# 10  
Old 08-26-2008
Quote:
Originally Posted by FractalizeR
fl1_load_modules_and_get_list() is called from lib/handle_install.sh

The line that calls it is:

Code:
$(fl_mod_${module}_pre_install)

It is called in a subshell and therefore is not loaded into the running environment.
# 11  
Old 08-26-2008
How to distinguish subshell calls from direct calls? $() is always a subshell?
# 12  
Old 08-26-2008
Quote:
Originally Posted by FractalizeR
How to distinguish subshell calls from direct calls? $() is always a subshell?
man bash:
COMMAND EXECUTION ENVIRONMENT
...
Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment...
# 13  
Old 08-26-2008
Thank you for links.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question