I know function has to be defined first - in sequence - before it can be used.
So the script has to be build "bottoms -up style, if you pardon my expression.
I am running into a problem reusing function and breaking the sequence.
It would be nice to be able to see the function usage tree as used in script.
Is there such a thing /application ?
Or - will bash complain when I have multiple definitions of a function to keep them in sequence?
I don't understand what you're trying to do. How does having multiple definitions of a function keep anything in sequence?
If you have defined a function more than once, the last function definition command executed for that function will be the one used when that function is invoked.
I don't understand what you're trying to do. How does having multiple definitions of a function keep anything in sequence?
If you have defined a function more than once, the last function definition command executed for that function will be the one used when that function is invoked.
Yuck, that sounds like a maintenance nightmare.
It is quite common to see a main function at the top a the script. Like this:
But you still need to keep the functions in the correct order, i.e callee before caller.
There is no need to have the functions in strict order. A function just needs to be known when it is invoked. Hence, if you put all the functions on the top of your script, you can arrange them in any order.
To be honest i prefer Korn shell over bash on any day of the week and twice on Sundays and this (the missing FPATH) is one of the reasons.
Still it is possible to get some sort of order in bash too: put every function in its own separate file, then use the source command to load these at the beginning of the script. This way you can't ever have two functions with the same name because the filesystem has distinct entries.
Note that this only pays off in big script projects. Scripts with 50-100 lines are easy to oversee but once the script gets several thousands of lines it is equally easy to lose track.
Still it is possible to get some sort of order in bash too: put every function in its own separate file, then use the source command to load these at the beginning of the script. This way you can't ever have two functions with the same name because the filesystem has distinct entries.
What a neat idea, I like it...
They make similar functions in other scripts effectively redundant.
I'm trying to call some functions in the background so that I can multitask in this script. Not working so hot. The functions I call don't ever seem to get called. I'm doing it the exact same way in another script and it's working like a champ so I'm very confused. Here's a pretty simple repro:
... (7 Replies)
I have a bash script with some functions as below and am wondering if I can use the variables declared in setup in the other functions and in the rest of the bash script.
setup(){
none=0; low=1; medium=2; high=3; debug=4
var1="red"
var2="fred"
}
create_basemap() {
... (7 Replies)
hi to all.
im a newbie in unix shell scripts. i want to make a simple unix shell script using the bash shell that asks a user to press any key after a series of commands, or an x if he wishes to exit. here's a sample script that i made:
#!/usr/bin/bash
pause(){
/usr/bin/echo "\t\t Press... (3 Replies)
Hi,
I have 4000 list files and 4000 sequence data files. Each list file contains a number of 'headers' and data file contains 'header and data'. I would like to extract data from the data file using the list file and write into a new file. As each of the files are quite large, an efficient piece... (6 Replies)
hi all,
hope someone can assist in this. I'm trying to make a sequence of time in bash so that the output prints the following;
1950-01-01
1950-02-01
1950-03-01
...
1999-11-01
1999-12-01
In R, i can issue the following command;
t1 <- ISOdate(1950,1,1,0,0,0)
t2 <-... (0 Replies)
Hello
Okay, for reasons related to sourcing a script from another script, I've had to put my main loop into a function, and from there I call other functions. My problem then is exiting from deep within the function call stack.
I used to simply call exit, and that would accomplish what I... (1 Reply)
This script is called fuu;
#!/bin/bash
speak() {
case $1 in
1)echo one
;;
2)echo two
;;
3)echo three
;;
esac
}
speak
exit 0
when i run fuu 2 i expect "two" like... (2 Replies)
Hi,
How can i do the mathematical calculations in bash shell?
Are the mathematical functions available in bash shell?
Ex:
pow
ceil
floor
sqrt (5 Replies)
Hello all,
Problem.
----------
I'm trying to reassign a referenced variable passed to a 'local'
variable in a function but the local variable refuses to be assigned
the content of the referenced variable.
Any ideas would be appreciated.
Objective.
-----------
Eliminate all $VAR... (1 Reply)
Hello.
I have the following problem with bash code:
function fl1_load_modules_and_get_list()
...........
for module in $FL_MODULES_TO_PROCESS
do
source "${FL_MODULE_DIR}/${module}/module.sh"
done
...........
}
function fl1_handle_install
{
local... (12 Replies)