【问题标题】:Continuation and comment together for bash? [duplicate]继续并一起评论 bash? [复制]
【发布时间】:2016-01-28 17:47:30
【问题描述】:

当我有很长的一行调用带有参数的命令时,是否可以将它分成几行,并对每一行进行推荐?

例如,如果我将free -h 分成两行

free \
-h

如何为每一行添加注释?像这样的尝试

free \ # this is the command
-h  # this is the argument

没用。

【问题讨论】:

标签: bash


【解决方案1】:

将参数存储在一个数组中,并在那里记录它们。

args=(--arg1      # First option
      --arg2 bar  # Second option with an argument
)

# Run free with the above arguments
free "${args[@]}"

【讨论】:

    【解决方案2】:

    一个经典的技巧是在反引号中使用内联的 cmets:

    free `#This is the command` \
    -h   `#This is the argument`
    

    【讨论】:

    • 一个昂贵的技巧,因为你必须为每条评论生成一个子shell。
    猜你喜欢
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    相关资源
    最近更新 更多