Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
3.2k views
3.2k views

How can I declare a function as "private" in Bash?

in Scripting
by (115)
2 18 33
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

Bash does not have the concept of public/private functions. All functions are public. However, it's common practice (across various programming and scripting languages including Bash) to let the names of functions begin with a double underscore if they're intended for private/internal use only.

__foo() {
  # this function is for internal use
  ...
}

bar() {
  # this function is for public use
  ...
}
by (115)
2 18 33
edit history
...