我一直在四處搜尋,試圖找到一個類似於我的答案,甚至是一個問題,並且一直無法這樣做。也許這裏有人可以幫忙。在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調用。 –