Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

bash - Importing shell script function

I have a function err() in file abc. The files do not have a .sh extension, but they start with #!/bin/bash.

err () {
    echo "${1}" >&2 
}

Now I am importing it in a different file xyz:

source abc
someFunction(){ 
    err "Failed to back up"
}

Is this the right way of importing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, you can do like you mentioned above or like: . FILENAME

The file need not to end with .sh


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...