Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我希望屏幕输出看起来像这样。
Ship to Bill to John Smith John Smith 222 Address 555 Address Los Angeles, CA New York, CA
如果不对空格进行硬编码,则会导致一旦第一列中条目的长度发生变化,第二列将不再对齐。
使用 printf 的示例:
#!/bin/bash st_name="John Smith" bt_name=$st_name st_addr="222 Address" bt_addr="555 Address" printf "%-20s%s\n" "Ship to" "Bill to" printf "%-20s%s\n" "$st_name" "$bt_name" printf "%-20s%s\n" "$st_addr" "$bt_addr"