Shell script for partiton and mounting

#!/bin/bash
# scan_add_fstab.sh
for i in /sys/class/scsi_device/*
do
  # must be a directory
  [ -d "$i" ] &&  echo "- - -" > "$i/device/rescan"
done
for b in $(lsblk -d | awk '$4=="6G" {print $1}')
do
  # jump to next loop cycle if /dev/$b is in fstab
  grep -q "^[^#]*/dev/$b\>" /etc/fstab && continue
  uuid=$(blkid -s UUID -o value /dev/$b)
  # jump to next loop cycle if its UUID is present and in fstab
  [ -n "$uuid" ] && grep -q "^[^#]*$uuid" /etc/fstab && continue
  # echo -e is discouraged, the echo options can differ between shells
  printf "o\nn\np\n1\n\n\nw\n" | fdisk /dev/$b
  partx -a /dev/$b
  mkfs.ext4 /dev/$b1
  uuid=$(blkid -s UUID -o value /dev/$b1)
  echo "UUID=$uuid  /root/abcd  ext4 defaults 0 0" >> /etc/fstab
done

uuid=$(blkid -s UUID -o value /dev/$b1)
why the above command does not give the value to the variable

Are you sure the b1 variable has a value assigned?

I found it now

it should be

uuid=$(blkid -s UUID -o value /dev/${b}1)

---------- Post updated 10-28-17 at 12:19 AM ---------- Previous update was 10-27-17 at 11:57 PM ----------

Here is the description
https://www.unix.com/shell-programming-and-scripting/274909-script-scan-disks-make-file-system.html

After testing the above script we come to conclusion that
the below lines check whether the the disk exists in that particular file[/etc/fstab] or not
if the partition exists with name or uuid it will skip and come out of the loop
but what if the disk are lvm partition is the question