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,202
Tak
  • 976
  • 3
  • 15
  • 34

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.

  • Is there a way to include all what is in the PATH environment variable found in ~/.bashrc? – Tak Sep 17 '19 at 11:53
  • 1
    That sounds like a different question: *"How do I search a file for PATH commands?"* – WinEunuuchs2Unix Sep 17 '19 at 12:28
  • I've updated the question with my script and output, could you please check? – Tak Sep 17 '19 at 12:57
  • 2
    You never posted the contents of /usr/local/MYPROGRAM/bin/myapp which you are both trying to include as a source file now and call as a program. Which is it a program to run our a source file to include? – WinEunuuchs2Unix Sep 17 '19 at 15:07
  • The myapp is called mrc2tif found here https://bio3d.colorado.edu/imod/doc/man/mrc2tif.html which is part of a program called IMOD – Tak Sep 18 '19 at 06:43