簡體   English   中英

在bash printf格式中如何在muliples占位符中使用相同的值

[英]in bash printf format how to use the same value in muliples placeholders

我想將文件的行數放在printf字符串的兩個占位符中

"%s lines: %s\n"
 ^          ^
 |here  and |here

所以我得到兩個wc -l ::

$ do_stuff() { 
printf "%s ## lines: %5s\n" \
`cat $1 | wc -l` \
`cat $1 | wc -l`;
} 
$ do_stuff ./lpm/modelisator.py
426 ## lines:   426
$

有用!

有沒有像python中的方式只給字符串一個值?::

In [1]: '{0} line {0}'.format(426)                                                                                                                             
Out[1]: '426 line 426'

使用支撐擴展

printf '%s lines: %s\n' "$(wc -l <"$1")"{,}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM