finding script name of function caller??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding script name of function caller??
# 1  
Old 04-19-2007
finding script name of function caller??

# utils.sh
#!/bin/sh

myfunc() {
echo "hello from myfunc"
}

#----------------------- begin caller script
# now myfunc is called in another script:
# and I'd like that myfunc echos the caller script!!!
#!/bin/sh

source ./utils

myfunc
#---------------------- end caller script

Any Ideas??

Thanks!!!
# 2  
Old 04-19-2007
use basename $0
# 3  
Old 04-20-2007
# utils.sh
#!/bin/sh

myfunc() {
echo "hello from myfunc"
echo "I am called from $0" # that outputs the name of the current function
# not the caller of the function :-((
}
# 4  
Old 04-20-2007
Code:
# utils.sh
#!/bin/sh

myfunc() {
echo "hello from myfunc"
echo "Caller script: $1"
}

#----------------------- begin caller script
# now myfunc is called in another script:
# and I'd like that myfunc echos the caller script!!!
#!/bin/sh

source ./utils

myfunc $( basename $0 )
#---------------------- end caller script

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

3. Shell Programming and Scripting

What is the function of the following lines at the top of a shell script file: Directory and Script?

The file starts like this: Directory: <path to the script> Script: <script fife name> #!bin/ksh ##Comments <actual script> What is the use of the first two lines in the script? What if I save the file without them? What will be the effect? They are not comments. Im very new to this,... (4 Replies)
Discussion started by: remytom
4 Replies

4. Shell Programming and Scripting

Passing variable from called script to the caller script

Hi all, Warm regards! I am in a difficult situation here. I have been trying to create a shell script which calls another shell script inside. Here is a simplified version of the same. Calling Script. #!/bin/ksh # want to run as a different process... (6 Replies)
Discussion started by: LoneRanger
6 Replies

5. Shell Programming and Scripting

shell script for finding average runtime of other script

so I've made a shell script that downloads 6 files in succession from a given url, then deletes them. Now I want to time the script, and the average time it uses by running it ~100 times. My problem is tho, how do I store the time it takes for each run through of the script? I know time writes to... (3 Replies)
Discussion started by: navlelo
3 Replies

6. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

7. Shell Programming and Scripting

Caller Script should produce and email from 4 different script within it

Hi I wrote a shell script , which includes one output file which is emailed back to me , when the script runs . Now i want to slip the script into 4 different shell scripts each of which taking the parameter PROD or DEV, and include all the 4 different shell scripts in a caller script. ... (3 Replies)
Discussion started by: rxg
3 Replies

8. UNIX for Advanced & Expert Users

Creating System Call, need PID of caller

Hey I am creating a new system call that needs to know the PID of the calling process. I am new to coding in the kernel, so I don't know if this is possible... Any help would be nice. Thanks! Hapatchi (4 Replies)
Discussion started by: Hapatchi
4 Replies

9. IP Networking

How to get Caller Id in PPP

hello I am workin with PPP to send data from dos machine to unix & Linux machine using FTP with help of fax & voice modem(Caller id Enabled & Exchange provides facility). i need to identify phone(number) connect with Dos machine i.e. to identify from where data is send. so i want to get the... (0 Replies)
Discussion started by: yspl
0 Replies

10. Shell Programming and Scripting

anti virus caller

Hi all. Iam using AVG antivirus personel edition, and i can only set it to run at one time only. Iam running it on a Win98 machine. is it possilbe to write a Perl script or c++ script to set it up to run at 12pm and 3pm and 6pm ??? (1 Reply)
Discussion started by: perleo
1 Replies
Login or Register to Ask a Question