[英]How can I print multiple variables using printf
我正在嘗試讓printf
在一行上輸出多個變量。
難以處理printf
參數處理和格式並接收意外的結果。
程式碼片段
printf '%s %s %s' $infile $insize $indate 2>&1 | tee -a $logfile
find $infile -printf ' %p %s %CY-%Cm-%Cd %CH:%CM:%.2TS \n' 2>&1 | tee -a $logfile
意外結果
*第一個文件大小未顯示,日期和時間不正確(printf)
*第二個文件大小正確,日期和時間不正確(查找-printf)
ftp://ftp.ncbi.nlm.nih.gov/pub/README.ftp 2019-08-25 00:00:00 ./README.ftp 2037 2019-08-25 14:22:26
預期結果
ftp://ftp.ncbi.nlm.nih.gov/pub/README.ftp 2037 2015-08-12 15:47:26 ./README.ftp 2037 2019-08-24 20:32:53
遠端檔案
Last-Modified: Wed, 12 Aug 2015 15:47:26 GMT
Content-Length: 2037
本地文件
2037 Aug 13 2015 README.ftp
提前致謝。
解
printf '%s %d %s' "$infile" "$insize" "$indate" 2>&1 | tee -a "$logfile"
find "$infile" -printf ' %p %s %CY-%Cm-%Cd %CH:%CM:%.2TS \n' 2>&1 | tee -a "$logfile"
結果
ftp://ftp.ncbi.nlm.nih.gov/pub/README.ftp 2037 2015-08-12 15:47:26 ./README.ftp 2037 2019-08-24 20:32:53
man 1 printf
關於參數處理的簡單明了的解釋。
GNU手冊的輸出轉換表,用於格式摘要
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.