AnswerBun.com

How to call .bashrc function in script

Unix & Linux Asked by young_souvlaki on September 14, 2020

~/.bashrc
----
example()
{
    echo "example function"
}

If I use this in a shell script

#!/bin/sh

example

I get command not found.

I have tried

#!/bin/sh

source ~/.bashrc
example

but it doesn’t work.


I found these answers and think this question deserves to live here with a clear question and clear and concise answer.

  1. Call a .bashrc function from a bash shell script
  2. How do you call a function defined in .bashrc from the shell?

One Answer

Another thing to consider is that even if you run your program with #!/bin/bash, it will not execute .bashrc, as it is a non interactive instance of bash.

Answered by user429927 on September 14, 2020

Add your own answers!

Related Questions

Set permanent environment variable for all shells

0  Asked on October 31, 2021 by user14492

         

How does jq work with keys containing slash?

1  Asked on October 31, 2021 by fhcat

 

GRUB not showing up in Pop!_OS

1  Asked on October 31, 2021

       

Set scale for bc inside a variable

1  Asked on October 31, 2021 by mdem7705

   

partition size vs file system size

1  Asked on October 31, 2021 by fa7eme

       

Explanation for “Killed Process”

1  Asked on October 31, 2021 by althor

 

tracking list of installed packages with git

2  Asked on October 31, 2021 by 400-the-cat

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir