[LEDE-DEV] [PATCH v3 04/13] scripts: $/${} is unnecessary on arithmetic variables

Sebastian Moeller moeller0 at gmx.de
Thu Oct 6 03:50:02 PDT 2016


Hi Jan-Tarek,

It might be not be necessary, but does it hurt? Are you concerned that the current practice will hide variables changing their "type" from arithmetic and that removing the $ prefix will silence this instead of giving an error message? Or does this change improve run time of the scripts noticeable? I am just asking, as a non-experts in shell coding it seems less error prone to always use ${VARIABLE_NAME}...

Best Regards
        Sebastian

On October 6, 2016 10:50:31 AM GMT+02:00, Jan-Tarek Butt <tarek at ring0.de> wrote:
>Signed-off-by: Jan-Tarek Butt <tarek at ring0.de>
>---
> scripts/om-fwupgradecfg-gen.sh | 10 +++++-----
> scripts/ubinize-image.sh       | 10 +++++-----
> 2 files changed, 10 insertions(+), 10 deletions(-)
>
>diff --git a/scripts/om-fwupgradecfg-gen.sh
>b/scripts/om-fwupgradecfg-gen.sh
>index 93f6794..5cbb8d1 100644
>--- a/scripts/om-fwupgradecfg-gen.sh
>+++ b/scripts/om-fwupgradecfg-gen.sh
>@@ -43,16 +43,16 @@ CHECK_BS=65536
> KERNEL_SIZE=$(stat -c%s "$KERNEL_PATH")
> KERNEL_MD5=$(md5=$(md5sum "$KERNEL_PATH"); echo "${md5%% *}")
>KERNEL_SHA256=$(openssl dgst -sha256 "$KERNEL_PATH" | awk '{print $2}')
>-KERNEL_PART_SIZE=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size *
>$FLASH_BS)) -lt "$KERNEL_SIZE" ] && size=$(($size + 1)); echo $(($size
>* $FLASH_BS / 1024)))
>+KERNEL_PART_SIZE=$(size=$((KERNEL_SIZE / FLASH_BS)); [ $((size *
>FLASH_BS)) -lt "$KERNEL_SIZE" ] && size=$((size + 1)); echo $((size *
>FLASH_BS / 1024)))
> 
>-ROOTFS_FLASH_ADDR=$(addr=$(($KERNEL_FLASH_ADDR + ($KERNEL_PART_SIZE *
>1024))); printf "0x%x" $addr)
>+ROOTFS_FLASH_ADDR=$(addr=$((KERNEL_FLASH_ADDR + (KERNEL_PART_SIZE *
>1024))); printf "0x%x" $addr)
> ROOTFS_SIZE=$(stat -c%s "$ROOTFS_PATH")
>-ROOTFS_CHECK_BLOCKS=$((($ROOTFS_SIZE / $CHECK_BS) - $MD5_SKIP_BLOCKS))
>+ROOTFS_CHECK_BLOCKS=$(((ROOTFS_SIZE / CHECK_BS) - MD5_SKIP_BLOCKS))
>ROOTFS_MD5=$(md5=$(dd if="$ROOTFS_PATH" bs=$CHECK_BS
>count=$ROOTFS_CHECK_BLOCKS 2>&- | md5sum); echo "${md5%% *}")
> ROOTFS_MD5_FULL=$(md5=$(md5sum "$ROOTFS_PATH"); echo "${md5%% *}")
>ROOTFS_SHA256_FULL=$(openssl dgst -sha256 "$ROOTFS_PATH" | awk '{print
>$2}')
>-ROOTFS_CHECK_SIZE=$(printf '0x%x' $(($ROOTFS_CHECK_BLOCKS *
>$CHECK_BS)))
>-ROOTFS_PART_SIZE=$(($MAX_PART_SIZE - $KERNEL_PART_SIZE))
>+ROOTFS_CHECK_SIZE=$(printf '0x%x' $((ROOTFS_CHECK_BLOCKS * CHECK_BS)))
>+ROOTFS_PART_SIZE=$((MAX_PART_SIZE - KERNEL_PART_SIZE))
> 
> cat << EOF > "$CFG_OUT"
> [vmlinux]
>diff --git a/scripts/ubinize-image.sh b/scripts/ubinize-image.sh
>index 1117e5b..d947bdd 100755
>--- a/scripts/ubinize-image.sh
>+++ b/scripts/ubinize-image.sh
>@@ -45,9 +45,9 @@ ubilayout() {
> 	local root_is_ubifs="$( is_ubifs "$2" )"
> 	if [ "$1" = "ubootenv" ]; then
> 		ubivol $vol_id ubootenv
>-		vol_id=$(( $vol_id + 1 ))
>+		vol_id=$(( vol_id + 1 ))
> 		ubivol $vol_id ubootenv2
>-		vol_id=$(( $vol_id + 1 ))
>+		vol_id=$(( vol_id + 1 ))
> 	fi
> 	for part in $parts; do
> 		name="${part%%=*}"
>@@ -63,14 +63,14 @@ ubilayout() {
> 		size="$part"
> 
> 		ubivol $vol_id "$name" "$image" "" "$size"
>-		vol_id=$(( $vol_id + 1 ))
>+		vol_id=$(( vol_id + 1 ))
> 	done
> 	if [ "$3" ]; then
> 		ubivol $vol_id kernel "$3"
>-		vol_id=$(( $vol_id + 1 ))
>+		vol_id=$(( vol_id + 1 ))
> 	fi
> 	ubivol $vol_id rootfs "$2" "$root_is_ubifs"
>-	vol_id=$(( $vol_id + 1 ))
>+	vol_id=$(( vol_id + 1 ))
> 	[ "$root_is_ubifs" ] || ubivol $vol_id rootfs_data "" 1
> }
> 




More information about the Lede-dev mailing list