Use external functions/modules in korn shell (ksh) August 7, 2007
Posted by claudio in GNU/Linux, General UNIX, Shell, Solaris.Tags: functions, ksh, modules, Programming, script, Shell, UNIX
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










This really helped me a lot.
Thanks