我不知道如何將以下行回顯到文件中。只有部分內容進入文件。
echo perl -e "printf(\"%.1lf%%\n\", ($reserved_block_count * 100.0 ) / $block_count);">>Show_Percent_Reserved_Blocks.sh
當我運行下面的腳本時,我得到
andyk_~/Downloads$ Show_Percent_Reserved_Blocks.sh
/home/andy/bin/Show_Percent_Reserved_Blocks.sh: line 2: Block: command not found
/home/andy/bin/Show_Percent_Reserved_Blocks.sh: line 3: Reserved: command not found
syntax error at -e line 1, near "/ )"
Execution of -e aborted due to compilation errors.
#!/bin/bash
Block count: 421958912
Reserved block count: 4219589
perl -e "printf(\"%.1lf%%\n\", ($reserved_block_count * 100.0 ) / $block_count);"
答案1
問題是,當您使用雙引號時,變數引用 ( $reserved_block_count
, $block_count
) 在目前(呼叫)shell 環境中被擴展;你需要用單引號引用整個內容:
echo 'perl -e "printf(\"%.1lf%%\n\", ($reserved_block_count * 100.0 ) / $block_count);"' >>Show_Percent_Reserved_Blocks.sh