In the following "one-liner," when I change the variable ID value at the start of the script, the disk variable that follows does not seem to update. Namely, at the end of the script, the >> /md0/DiskAnalysis/$disk.txt portion uses the value of the $disk variable that was generated by a different $ID variable value than the one defined at the start of the script.
Full one-liner script
nohup sh -c ID="c"; disk=`udevadm info --query=all /dev/sd$ID | grep ID_SCSI_SERIAL | awk -F'=' '{print $2}'`; size=`lsblk -b --output SIZE -n -d /dev/sd$ID`; size=`echo "$size / 1024 / 1024 / 10" | bc`; for i in $(seq 0 $size); do dd if=/dev/sd$ID of=/dev/shm/$ID.dd bs=10M skip=$i count=1 2>1; sha256=`sha256sum /dev/shm/$ID.dd | awk -F' ' '{print $1}'`; md5=`md5sum /dev/shm/$ID.dd | awk -F' ' '{print $1}'`; echo "$i,$sha256,$md5" >> /md0/DiskAnalysis/$disk.txt; done &
So, when I change ID="b" to ID="c", the
disk=`udevadm info --query=all /dev/sd$ID | grep ID_SCSI_SERIAL | awk -F'=' '{print $2}'`
portion of the script does not update its value to reflect the change in the $ID variable value. However, If I were to execute the following by itself in terminal:
ID="b"; disk=`udevadm info --query=all /dev/sd$ID | grep ID_SCSI_SERIAL | awk -F'=' '{print $2}'`; echo $disk
and
ID="c"; disk=`udevadm info --query=all /dev/sd$ID | grep ID_SCSI_SERIAL | awk -F'=' '{print $2}'`; echo $disk
I get two different values for $disk.
What am I missing that is resulting in the $disk variable value not updating in the full script?
For the moment, I am assuming the change in the $ID value in other parts of the script (i.e. the checksums) is working correctly. However, since the $disk value is not updating correctly, the output isn't writing to the desired file. In fact, every time I run the script with an $ID value different from the original (ID="b"), the output from the rest of the script simple writes to the output file (i.e. $disk) defined by the first original $ID.
Thanks.