简体   繁体   English

如何在 bash 中为 printf 的每一行添加评论?

[英]How do I put comment on each line in bash for printf?

I have the following code in my Dockerfile .我的Dockerfile中有以下代码。 Then I piped the output to my setup.py .然后我将 output 传送到我的setup.py I need to run this command in linux terminal.我需要在 linux 终端中运行此命令。 How can i put comment on each line?我怎样才能在每一行上发表评论?

  printf "%s\n" \
    # Facebook OAuth Client ID (default)
    "1234" \
    # Facebook OAuth Secret (default)
    "abcd" \
    # Google OAuth Client ID (default)
    "5678" \
    # Google OAuth Secret (default)
    "qwer" \

Using arrays in order to avoid long escaped by \ lists of arguments is a good practice.使用 arrays 以避免被 arguments 的\列表长时间转义是一个很好的做法。 You can leave a comment for each element.您可以为每个元素留下评论。

CREDENTIALS=(
    # Facebook OAuth Client ID (default)
    "1234"
    # Facebook OAuth Secret (default)
    "abcd"
    # Google OAuth Client ID (default)
    "5678"
    # Google OAuth Secret (default)
    "qwer"
)
printf "%s\n" "${CREDENTIALS[@]}"
printf "%s\n" \
    $(: 'Facebook OAuth Client ID (default)') \
    "1234" \
    $(: 'Facebook OAuth Secret (default)') \
    "abcd" \
    $(: 'Google OAuth Client ID (default)') \
    "5678" \
    $(: 'Google OAuth Secret (default)') \
    "qwer"

$(command) is command substitution, it gets replaced with the output of the command. $(command)是命令替换,它被命令的 output 替换。

: is a command that does nothing and produces no output. :是一个不执行任何操作且不产生 output 的命令。 The argument needs to be quoted because of the (default) , which would otherwise be executed as a command in a subshell.由于(default) ,该参数需要被引用,否则它将作为子shell中的命令执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM