无法将整行回显到文件

无法将整行回显到文件

我不知道如何将下面一行回显到文件中。只有部分内容进入了文件。

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

相关内容