0

I have an app on my Ubuntu machine installed in /usr/local/MYPROGRAM/bin/myapp. When I try using myfn in my bash script mybashscript.sh it gives an error saying that the myfn command is not found, but if I call myfn from a normal terminal window it works fine since it's found in the ~/.bashrc file. How I can call myfn from my bash script mybashscript.sh?

Here is mybashscript.sh:

#!/bin/bash -i

alias brc='source ~/.bashrc'

source /usr/local/MYPROGRAM/bin/myapp
#exec bash
echo "******************pathhhhhhhh************"
echo $PATH
echo "******************pathhhhhhhh************"
/usr/local/MYPROGRAM/bin/myapp

This is the output when I run ./mybashscript.sh:

bash: /bin/realbin/myapp: No such file or directory
******************pathhhhhhhh************
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
******************pathhhhhhhh************
/usr/local/MYPROGRAM/bin/myapp: 3: /usr/local/MYPROGRAM/bin/myapp: /bin/realbin/myapp: not found
K7AAY
  • 17,705
Tak
  • 976
  • 3
  • 16
  • 35

1 Answers1

1

To make the function visible to your script you need to "source" the file into your script with:

source /usr/local/MYPROGRAM/bin/myfn

or:

. /usr/local/MYPROGRAM/bin/myfn

This will include all the defined functions, variables and constants within the file into your script.