Sponsored Content
Top Forums Shell Programming and Scripting Call functions from other scripts Post 302984874 by Don Cragun on Tuesday 1st of November 2016 10:59:20 PM
Old 11-01-2016
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:
Code:
results=$(/var/home/functions.sh ; myTest ; myCar)

to:
Code:
results=$(. /var/home/functions.sh ; myTest ; myCar)

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:
Code:
. /var/home/functions.sh
results=$( myTest ; myCar)
MYPWD=$(echo "${results}" | egrep MYPWD | awk -F"=" '{print $2}')
MYLOGNAME=$(echo "${results}" | egrep MYLOGNAME | awk -F"=" '{print $2}')
MYDATE=$(echo "${results}" | egrep MYDATE | awk -F"=" '{print $2}')
MYUPTIME=$(echo "${results}" | egrep MYUPTIME | awk -F"=" '{print $2}')

This User Gave Thanks to Don Cragun For This Post:
 

9 More Discussions You Might Find Interesting

1. Programming

call functions from diferents programs

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)
Discussion started by: DebianJ
1 Replies

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

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

4. Shell Programming and Scripting

Bash: Nested functions and including other scripts

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)
Discussion started by: FractalizeR
12 Replies

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

6. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

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)
Discussion started by: Yoodit
2 Replies

7. Programming

can a linux kernel module call libc functions?

can a linux kernel module call libc functions, such as printf(), strcpy(), etc...? (9 Replies)
Discussion started by: vistastar
9 Replies

8. Shell Programming and Scripting

How to call different scripts?

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)
Discussion started by: priyanka.premra
1 Replies

9. Shell Programming and Scripting

Help Modify call to functions depending on file name

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)
Discussion started by: pinnacle
2 Replies
PPPOE-SETUP(8)						      System Manager's Manual						    PPPOE-SETUP(8)

NAME
pppoe-setup - Shell script to configure Roaring Penguin PPPoE client SYNOPSIS
pppoe-setup DESCRIPTION
pppoe-setup is a shell script which prompts you for various pieces of information and sets up an /etc/sysconfig/network-scripts/ifcfg-ppp0 configuration script for the pppoe-start, pppoe-stop and +pppoe-connect scripts. AUTHOR
pppoe-setup was written by David F. Skoll <dfs@roaringpenguin.com>. The pppoe home page is http://www.roaringpenguin.com/pppoe/. SEE ALSO
pppoe(8), pppoe-start(8), pppoe-stop(8), pppoe-connect(8), pppd(8), pppoe.conf(5), pppoe-status(8), pppoe-sniff(8), pppoe-relay(8), pppoe- server(8) 4th Berkeley Distribution 21 February 2000 PPPOE-SETUP(8)
All times are GMT -4. The time now is 05:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy