In AIX, I have a, FPATH set function, which is globally accessible by just calling the function name. I am trying to replicate this functionality in Linux. I set the function in $PATH variable, I tried sourcing the script. But still I get Function not found error.

If I call the function script with absolute path, it works. example: FmtMg is the function I place the file in /usr/local/lib directory

export $PATH=$PATH:/usr/local/lib/FmtMg
source /usr/local/lib/FmtMg

I tried all these above, it still fails. Below is the script to test the function.

set -u # all variables must be set

unset -f FmtMg
autoload FmtMg

GM=`basename $0`

print "Testing FmtMg\n"

FmtMg  -p$GM -l$LINENO -s0 "FmtMg Test Completed."
  • Note that if you have an executable script /usr/llocal/lib/FmtMg then you want PATH=...:/usr/local/lib, not .../usr/local/lib/FmtMg – Jeff Schaller Dec 4 '18 at 2:04
  • Thank you, I did that but it did not help, I still get Function not found – Bootham Deyyam Dec 4 '18 at 15:19

FPATH is a ksh feature, which is probably the shell you used on AIX. I do not believe bash works this way, and that's probably the shell you're using on Linux.

If you use ksh93 on Linux (e.g. yum install ksh on CentOS/RedHat; apt-get install ksh on Debian) and set your login shell to that, then it will work the same way. (I recommend ksh93 and not pdksh because pdksh isn't fully compatible).

On my machine:

$ echo ${.sh.version}
Version AJM 93u+ 2012-08-01

$ grep FPATH ~/.profile 
export FPATH=$HOME/fns

Inside that directory I have a function definition for "loop'

$ head -3 $FPATH/loop
# A loop function: loop var from to 'commands'
function loop

Before I use it we can see that ksh knows it's a function, but not yet defined

$ whence -v loop
loop is an undefined function

And when I attempt to use it, ksh auto defines it from the $FPATH entry

$ loop i 1 5 'echo $i'

$ whence -v loop      
loop is a function
  • Thank you, the requirement is, I cannot use FPATH anymore. I just want to define the executable in my profile, so when any shell script that references the function executes, the function should be recognized. Now for Linux my profile is set to use ksh and not bash. – Bootham Deyyam Dec 4 '18 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.