Bash scripting question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash scripting question
# 1  
Old 03-12-2012
Bash scripting question

have a script that calls child scripts depending on conditions. All of the child scripts source in a common file that contains shared functions.

At the moment each script has to source this file itself, is there a way for the master script to automagically source the file for them?

For clarity, right now the parent script is executing:

Code:
$theScriptPath $theParameters 2>&1 | tee $theOutput

right now the $theScriptPath file has to include the following line:

Code:
. /sharedFiles/commonFunctions

Can I do something magical in the parent script that will make this unnecessary?

Last edited by methyl; 03-12-2012 at 08:55 PM.. Reason: please ue code tags
# 2  
Old 03-12-2012
Just use:
export -f FunctionName
in commonFunctions eg:

Code:
$ cat parent
. ./commonFunctions
./child
$ cat commonFunctions
function hash {
   echo "This is the hash function"
}
export -f hash
$ cat child
hash
$ ./parent
This is the hash function

# 3  
Old 03-12-2012
I did this for one of my scripts in the past by making the master script be a front end for each individual script. The master invoked itself as a new process instance by using an option after the command name that told itself which thing to do. I used a triple dash option for that. When the master script saw a triple dash option, it checked for the existing of the individual script based on the characters after the triple dash. Then it sourced (or had already coded in it) the common functions. Then it SOURCED the individual script instead of running it, since this instance was already in a new process.
# 4  
Old 03-13-2012
thanks Chubler_XL, worked perfect.

Cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Total Noob BASH scripting question

Hello All, I have a file of ip addresses called activeips.txt What I'm trying to do is run a simple bash script that has a loop in it. The loop is a cat of the IP addresses in the file. The goal is to run 2 nmap commands to give me outputs where each address in the list has an OS... (11 Replies)
Discussion started by: Dirk_Pitt
11 Replies

2. Shell Programming and Scripting

Beginner Bash Scripting Question

Hello, I am new to Linux and studying to become a Unix System Admin. I am taking a course in which I was practicing creating a bash script to ping a particular IP address. The script can be found below: #/bin/bash echo "Enter the IP address" read ip if then ping -c 1 $ip if ;... (3 Replies)
Discussion started by: shah9250
3 Replies

3. Shell Programming and Scripting

bash scripting

same script: 1- i am using grep to find a string called: tinker panic 0 in a file /etc/ntp.conf if the string is not there, i want to add the strings in /etc/ntp.conf file in the first line of the file. if not do nothing or exit. 2- also i want to add # in front of the following lines in... (0 Replies)
Discussion started by: lamoul
0 Replies

4. Shell Programming and Scripting

Bash scripting

Try to imagine a flag: nnnnx nnnxx nnxxx nxxxx now imagine how it will output: 4 times the "n"and 1 times "x" 3 times "n"and" 2 times" x " .. etc. .. rhombus is the same only instead of "n" is there gap "and " x "is a few times to form the correct shape Can you help... (3 Replies)
Discussion started by: krcek12
3 Replies

5. Shell Programming and Scripting

Bash scripting, question about a variable

Hey, So I've run into a problem, due to my limited knowledge of Bash scripting. Basically I've got a long script and I want to understand it before I even try and edit it. As long as I don't understand the script, I will not bother editing it. Anyway, the following variable confuses me... (5 Replies)
Discussion started by: abciscool
5 Replies

6. Shell Programming and Scripting

please help with Bash Scripting????

Hi, can anyone help me with my scrip please. I wanted do following tasks: 1. List all the directory 2. A STDIN to ask user to enter a directory name from listed directories 3. command to check if the directory exists( or a command to validate if the user entered a valid directory name) ... (2 Replies)
Discussion started by: eminjan
2 Replies

7. Shell Programming and Scripting

bash scripting help

hi all i'm trying to get a script working upon connection with pppd According to docu this happens ina clean environment with a couple of variables set, namely $1,$2,... To be able to execute the statements i included a path statement but i think i'm running into trouble with the variables -... (6 Replies)
Discussion started by: jimjones
6 Replies

8. UNIX for Dummies Questions & Answers

Should I do a bash scripting course?!

Hello, I'm confused (oh, yes). I'm running Linux at work. When I type 'echo $SHELL' I am told that I'm running tcsh. In /bin I note that both tcsh and bash are listed. Question 1: Can I swap to run bash rather than tcsh and, if so, how will this affect my system? Is there any advantage to... (6 Replies)
Discussion started by: macpete
6 Replies

9. Shell Programming and Scripting

Bash scripting question re: newlines

I'm writing a bash script to search the contents of a postfix log. To keep the script's output readable (since multiple lines from the log file need to be echo'ed) I am setting the IFS variable to an empty string so that the line breaks in my grep results are preserved. I am storing the results... (4 Replies)
Discussion started by: retrovertigo
4 Replies
Login or Register to Ask a Question