我一直在四处搜寻,试图找到一个类似于我的答案,甚至是一个问题,并且一直无法这样做。也许这里有人可以帮忙。在bash脚本的列中打印文本
我试图从我的bash命令打印帮助文本。我希望命令/选项位于一列中,而第二列中的解释如果文字环绕,则从正确的列编号开始。
我试过printf
,我不太明白column
命令。
下面是我想:
myscript.sh Execute without arguments to get a menu
of options defining the environment.
myscript.sh [url] Add [url] to specify desired server
environment with which to run the script.
ex: http://the.server.domain.tld:port/
我的尝试,迄今为止,看起来像:
col1="%-15s"
col2="%15s\n"
printf "$col1" "myscript.sh"
printf "$col2" "Execute without arguments to get a menu of options defining the environment."
printf "$col1" "myscript.sh [url]"
printf "$col2" "Add [url] to specify desired server environment with which to run the script."
printf "$col2" "ex: http://the.server.domain.tld:port/"
,但它结束了看起来像
myscript.sh Execute without arguments to get a menu
of options defining the environment.
myscript.sh [url] Add [url] to specify desired server
environment with which to run the script.
ex: http://the.server.domain.tld:port/
如果你想要与第一格式的2列,只使用'COL2 = “%S \ n” 个'或用于连续行col2你仍然必须打印col1。例如在你的最后一个printf之前,添加'printf'$ col1“”“'实际上,你应该将你的格式合并成一个'col =”% - 15s%s“',然后将这两个值提供给一个printf调用。 –