Errors running perl statement

When I run this

#!/bin/bash
Block count:              421958912
Reserved block count:     4219589
perl -e "printf(\"%.1lf%%\n\", ($Reserved block count * 100.0 ) / $Block count);"

I get these error messages. Can someone please help me?

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.

You are trying to execute every line in your script. Are you trying to assign the values to variables and then use that in the perl command?

Perhaps this would be better:-

#!/bin/bash
Block_count=421958912
Reserved_block_count=4219589

perl -e "printf(\"%.1lf%%\n\", ($Reserved_block_count * 100.0 ) / $Block_count);"

Note that the variable names do not include spaces. The underscore is permitted, but a hyphen or full stop are not.

Does this help?
Robin

Your script will not work because block count and reserved block count are not in the script themselves.

Another bash script created another script with Block count: and Reserved block count: in them.

Here is that script.

cd /home/andy/Downloads/
echo xxxx | sudo -S tune2fs -l /dev/sda1 > list_tune.txt
# looks for block count and IS case insensitive
#
echo "#!/bin/bash" > Show_Percent_Reserved_Blocks.sh
grep -i "block count" list_tune.txt >>Show_Percent_Reserved_Blocks.sh
echo 'perl -e "printf(\"%.1lf%%\n\", ($reserved_block_count * 100.0 ) / $block_count);"' >>Show_Percent_Reserved_Blocks.shecho xxx |sudo -S chmod +x Show_Percent_Reserved_Blocks.sh

---------- Post updated at 08:15 AM ---------- Previous update was at 07:59 AM ----------

I see my problem.

I need to execute the perl script outside of a bash script.

Which is another step that I want to avoid.

Would you not be better with something else then, such as:-

#!/bin/bash

read a b block_count < <(grep -i "block count" list_tune.txt | grep -iv reserved)
read a b reserved_block_count < <(grep -i "reserved block count" list_tune.txt)

echo "\$block_count=\"$block_count\""
echo "\$reserved_block_count=\"$reserved_block_count\""
echo

perl -e "printf(\"%.1lf%%\n\", ($reserved_block_count * 100.0 ) / $block_count);"

Does that help a bit? This tries to read your input file and assign the variables before calling the perl command in a single script without trying to automate a code-writer/runner, which are notoriously difficult to assure.

Robin

Thanks Robin for your help.