BASH中参数之间的评论

Dor*_*Dor 6 bash comments

我想包含命令参数 - 内联注释,例如:

sed -i.bak -r \
    # comment 1
    -e 'sed_commands' \
    # comment 2
    -e 'sed_commands' \
    # comment 3
    -e 'sed_commands' \
    /path/to/file
Run Code Online (Sandbox Code Playgroud)

上面的代码不起作用.在参数行中嵌入注释有不同的方法吗?

jm6*_*666 9

如果你真的想要评论参数,可以试试这个:

ls $(
    echo '-l' #for the long list
    echo '-F' #show file types too
    echo '-t' #sort by time
)
Run Code Online (Sandbox Code Playgroud)

这相当于:

ls -l -F -t
Run Code Online (Sandbox Code Playgroud)

echo是内置的shell,因此不执行外部命令,所以它足够快.但是,无论如何它都很疯狂.

要么

makeargs() { while read line; do echo ${line//#*/}; done }
ls $(makeargs <<EOF
        -l # CDEWDWEls
        -F #Dwfwef
EOF
)
Run Code Online (Sandbox Code Playgroud)