make a shell script with fewer lines

88 views Asked by At

I always disbale all the IOSTAT in my android's memory IOBLOCKS and just wanted to make this code into a fewer lines

Is it possible:

#!/system/bin/sh

echo 0 > /sys/block/sda/queue/iostats
echo 0 > /sys/block/sdb/queue/iostats
echo 0 > /sys/block/sdc/queue/iostats
echo 0 > /sys/block/sde/queue/iostats
echo 0 > /sys/block/sdf/queue/iostats
echo 0 > /sys/block/sdd/queue/iostats
2

There are 2 answers

0
AudioBubble On BEST ANSWER
#! /system/bin/sh -
echo 0 | tee /sys/block/sd[a-f]/queue/iostats
0
Ron On

One liner, chopped to few lines so it's easier to read:

#!/system/bin/sh
for z in a b c d e f;do
  echo 0 > /sys/block/sd${z}/queue/iostats
done

This solution uses only echo, and no other apps like tee, awk, grep...

via Bash it can be even shorter with: {a..f}, but I see you want/need to use sh