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 execute the functions file so its information becomes available to the other script?
In linux use the source command or more generally the lonely dot operator.
Oh:
PS: make sure the functions script does not call exit except on a fatal error. Since it runs in the process context of the calling script, exit or some signals initiated in the functions script will stop everything.
We have a db startup/error exit/exit functions script that does all manner of stuff. We source it and every one of hundreds of scripts run the exact same thing. Great for minimizing the source of problems. problems.
Last edited by jim mcnamara; 11-01-2016 at 11:14 PM..
This User Gave Thanks to jim mcnamara For This Post:
Expanding a little bit on what Jim already said...
It is ALWAYS a good idea to tell us what shell and operating system you're using when you ask a questions like this! The way to do this varies from shell to shell. Assuming that you are using a shell that is based on Bourne shell or POSIX shell syntax, that the functions file only defines functions and/or variables that your script will want, that the functions file does not invoke any commands or functions that you don't want your script to execute, and that the function definitions are suitable for the shell that will be running your script; you bring those functions into your script by dotting the function file before you reference any of the functions you want to invoke from that function file.
If you only want to reference those functions in the subshell environment that is set up to run the 1st command substitution in otherscript.sh, you could change the 1st line you showed us in that file from:
to:
If you want to reference those functions in other places in otherscript.sh including inside and/or outside any other subshells it starts, dot your function file before you invoke any subshells:
This User Gave Thanks to Don Cragun For This Post:
im hoping someone can help me understand this better.
so the problem here is, the client has complete control over the functions.sh script. meaning, i cant see the content of it.
so, while sourcing it with a:
works in most ordinary situations, im curious if there are other options.
for instance, suppose the customer has the following in their functions.sh file:
then, in my script otherscript.sh, I do something similar to this:
will this work?
of course, the problem i see right off the bat is that, yes, the above will run the function within the functions.sh file. but what if i needed it to run inside the otherscript.sh script and make the resources generated from it available to otherscript.sh?
I presume at some point, the export command will be used somewhere.
Hi,
I am creating a script that does gunzip/unzip/untar depending on the file extension.
I have created 3 functions in my script and call them in following order.
1) gunzip function
2) unzip function
3) untar function
I am using FILENAME=${FILENAME%.*} to modify filename between... (2 Replies)
I have 3 different scripts with 3 different functions, I would like to merge these 3 and make a master script.
The following are my ideas:
- ask user to pick which script he needs
- after choosing, point it to the right script
or...
depending on the inputs provided by the user, all three... (1 Reply)
Dear Members,
I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc.
I would like to create a script which will will call other scripts based on the request action.
Can we directly read from the REQUEST_ACTION... (2 Replies)
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)
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)
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)
hi
i have ten program in C, and there are functions what are in all the programs.
so, i want to make a directory to store all the functions what are in all the programs, and call them from the C programs. (sending variables and values)
is that possible?¿? how ca i do that?¿?
any idea,... (1 Reply)