jump to navigation

Use external functions/modules in korn shell (ksh) August 7, 2007

Posted by claudio in Uncategorized.
Tags: , , , , , ,
trackback

The korn shell is a great shell to write shell scripts. Some functionalities are really nice. By example, you can write your functions or modules in a separate file and use it within your program. The secret lies in the FPATH environment variable.

root@labo:~/tmp# tree
.
|-- main.ksh
`-- modules
___`-- module
1 directory, 2 files

root@labo:~/tmp# cat modules/module
module() {
echo The module works
}

root@labo:~/tmp# cat main.ksh
#!/bin/ksh
echo "If I get an answer, the module works:"
module

root@labo:~/tmp# ./main.ksh
If I get an answer, the module works:
./main.ksh[3]: module: not found

root@labo:~/tmp# FPATH=/export/home/claudio/tmp/modules
root@labo:~/tmp# export FPATH
root@labo:~/tmp# ./main.ksh
If I get an answer, the module works:
The module works

About these ads

Comments»

1. Robert - December 11, 2008

This really helped me a lot.

Thanks


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 142 other followers

%d bloggers like this: