How to call the function of .bashrc correctly?

The following sentences are found in

.bashrc.

var="xxx"
fun1(){
    echo $var
}
export -f fun1

there was a problem calling the fun1 function in .bashrc from test.sh and could not get the value of var.
I rewrote

fun1(){
    var="xxx"
    echo $var
}
export -f fun1

you can call fun1 from test.sh.

there are two problems:
1.var= "xxx" needs to be called by other functions in .bashrc. Many people write a few more var= "xxx"
2.export-f fun1
if there are 10 functions that want to be called by other scripts from .bashrc, write 10 export-f funm?

.

how to solve these two problems properly?

Mar.03,2021

store shared variables and functions in a separate file and introduce it when you need to call it.

for example, here are the contents of the shared file common.source

author=""

function print_name() {
    echo "name: $1"
}

suppose you need to call foo () in the a.sh file, you can write

like this.
-sharp!/bin/bash
source common.source
print_name $author

question 1:
if you want to read $var, and export it in another script, you don't have to write it in the function.

question 2:
I think you mean ".bashrc has 10 functions that need to be called by other scripts". The answer is, you don't need to write 10 export, or even $var you don't use export. Just add set-a to the variables and functions that need export, and then the variable assignments and function definitions are automatically export.

-an Each variable or function that is created or modified is given the export attribute and marked for export to the environment of subsequent commands.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b384d4-2c12f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b384d4-2c12f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?