[英]How to get a particular argument in printf format in bash?
需要構建一個字符串foobar is not foo and not bar
。
我期待類似的代碼:
$ printf "%1%2 is not %1 and not %2" 'foo' 'bar'
那么,如何傳遞特定的論點呢?
我的環境:
$ bash --version
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
語法與C printf函數中的語法相同。
$ printf '%1$s%2$s is not %1$s and not %2$s' 'foo' 'bar'
實際上,如果只需要連接一些字符串,則不需要printf
。 您可以在字符串中使用命名變量:
a=foo
b=bar
echo "$a$b is not $a and not $b"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.