korn shell - export function??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting korn shell - export function??
# 1  
Old 04-07-2010
korn shell - export function??

Hi,

I have a question. I know that if I want to access any variables defined in a calling script (script1.ksh) in a called script (script2.ksh) I need to export that variable in the calling script to make it available in the called script. But what about the functions in the calling script?

script1.ksh
Code:
export var1=InScript1
function todayDate
{
         echo $(date)
}

script2.ksh
Code:
 
echo $var1

If I call the script1.ksh in script2.ksh then I can access all the functions & variables (without exporting) of script1.ksh like below:

script2.ksh
Code:
 
. /home/dips/script1.ksh
 
todayDate

If suppose I don't want to include the whole of the script1.ksh but want to access only parts of it as in few variables and a function then is it possible?
-dips
# 2  
Old 04-07-2010
Put the functions in a separate file and source them from each script that requires them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Export a function to another function

is there a way to export a function to another function? i'm using #!/usr/xpg4/bin/sh in the first line of my script. firstfunc () { echo $1 is nice } secondfunc () { firstfunc Nancy } when i run a similar scenario to the above, i get: /usr/xpg4/bin/sh: firstfunc: not found (4 Replies)
Discussion started by: SkySmart
4 Replies

2. Shell Programming and Scripting

Multithreading - Calling user function with xargs in korn shell

I know there are other ways of accomplishing the below task, but the purpose of this thread is to understand the below code. I wanted to use xargs with user defined function in korn shell. Am aware, that I could write custom function into a script and place it in FPATH and then call it in xargs,... (2 Replies)
Discussion started by: luhah
2 Replies

3. Shell Programming and Scripting

Pass values to case statement in a function korn shell

I'm in the process of writng a function that consists of a case statement is there a way of calling the function and passing a value to it? ie function1 () { case opt1 do ..... opt2 do..... esac } function opt1 I'm aware the syntax is not correct, but you get the general idea. (1 Reply)
Discussion started by: squrcles
1 Replies

4. Shell Programming and Scripting

How to export the function in ssh

Hi Gurus, I have a requirment to use a function created in a script in another server within the script. Below is the sample script for reference #/bin/bash logs_gen () { XXXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXX } for i in x y z; do # x y z are the server... (7 Replies)
Discussion started by: raghu.iv85
7 Replies

5. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 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

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

8. Shell Programming and Scripting

putting ftp in korn function - no longer working

This works if it's not in a function. I pulled it into one and I get syntax error, no mathcing '<'. I have to call it several times and need it to be a function. Any ideas? function FTP_Engine_File { ftp -inv ${FTP_SERVER} << EOF_FTP >> ${FTP_LOG} user ${FTP_USER} ${FTP_PSWD} ... (4 Replies)
Discussion started by: brdholman
4 Replies

9. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

10. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question