簡體   English   中英

是否存在在bash中命名“私有函數”的約定?

[英]Is there a convention for naming 'private functions' in bash?

是否存在在bash中命名私有函數的約定? 我有一個帶有一些私有函數的bash模塊,想知道我是否應該用下划線開始它們的名字。 到目前為止,我還沒有看到任何慣例。

對於它的價值,Red Hat的/etc/init.d/functions腳本使用雙下划線。

# __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'

我不知道任何正式的特定於bash的約定,但是使用下划線啟動私有標識符是一種相當普遍的與語言無關的約定(我在從C到Perl到Java到shell腳本的任何事情上遇到過它)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM