views:

129

answers:

2

Is there a convention for naming private functions in bash? I have a bash module with some private functions, wondering if I should start their names with underscore. So far I haven't seen any convention.

+1  A: 

I'm not aware of any formal bash-specific conventions, but starting private identifiers with underscore is a fairly widespread language-independent convention (I encountered it on anything from C to Perl to Java to shell scripts).

DVK
+2  A: 

For what it's worth, Red Hat's /etc/init.d/functions script uses double underscores.

# __umount_loop awk_program fstab_file first_msg retry_msg umount_args
# awk_program should process fstab_file and return a list of fstab-encoded
# paths; it doesn't have to handle comments in fstab_file.
__umount_loop() {
    # ...
}

# Similar to __umount loop above, specialized for loopback devices
__umount_loopback_loop() {
    # ...
}

# __proc_pids {program} [pidfile]
# Set $pid to pids from /var/run* for {program}.  $pid should be declared
# local in the caller.
# Returns LSB exit code for the 'status' action.
__pids_var_run() {
    # ...
}

# A sed expression to filter out the files that is_ignored_file recognizes
__sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d'
John Kugelman