From 8784bda9899bbf2d8aba42c992630c154a2ce8a1 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Mon, 22 Jan 2018 02:33:33 +0000 Subject: [PATCH] Avoid calling identical commands multiple times --- pishrink.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pishrink.sh b/pishrink.sh index b1a89ca..188ce73 100755 --- a/pishrink.sh +++ b/pishrink.sh @@ -48,11 +48,13 @@ fi #Gather info beforesize=$(ls -lah "$img" | cut -d ' ' -f 5) -partnum=$(parted -ms "$img" unit B print | tail -n 1 | cut -d ':' -f 1) -partstart=$(parted -ms "$img" unit B print | tail -n 1 | cut -d ':' -f 2 | tr -d 'B') +parted_output=$(parted -ms "$img" unit B print | tail -n 1) +partnum=$(echo "$parted_output" | cut -d ':' -f 1) +partstart=$(echo "$parted_output" | cut -d ':' -f 2 | tr -d 'B') loopback=$(losetup -f --show -o $partstart "$img") -currentsize=$(tune2fs -l $loopback | grep 'Block count' | tr -d ' ' | cut -d ':' -f 2) -blocksize=$(tune2fs -l $loopback | grep 'Block size' | tr -d ' ' | cut -d ':' -f 2) +tune2fs_output=$(tune2fs -l $loopback) +currentsize=$(echo "$tune2fs_output" | grep 'Block count' | tr -d ' ' | cut -d ':' -f 2) +blocksize=$(echo "$tune2fs_output" | grep 'Block size' | tr -d ' ' | cut -d ':' -f 2) #Check if we should make pi expand rootfs on next boot if [ "$should_skip_autoexpand" = false ]; then