Bash read line not parsing correct - ideas?

For the the life of me, I can't find the cause, or workaround, to the fact that the read line is not parsing correctly. :frowning:

specifications="./partitions_sdg_specs.conf"

cat >"${specifications}" <<EnDoFfIlE
# partNum:partFsType:partStart:partEnd:partName:partMount
1	swap	4MiB	8GiB	HIBERNATE	none
2	ext4	8GiB	12GiB	BOOT		/boot
3	ext4	12GiB	200GiB	DB007_F1	/
4	ext4	200GiB	100%	DB007_F2	/DB007_F2
EnDoFfIlE

IFSorig="${IFS}"

grep -v '^#' "${specifications}" |
while [ true ]
do
	#read line

	IFS=':' read partNum partFsType partStart partEnd partName partMount
	if [ $? -ne 0 ] ; then break ; fi

	echo "	partNum		= ${partNum}
	partFsType	= ${partFsType}
	partStart	= ${partStart}
	partEnd		= ${partEnd}
	partName	= ${partName}
	partMount	= ${partMount}"
done

IFS="${IFSorig}"

I've tried that with and without the -r option for read. :frowning:


The output I am getting is this, instead of the expected distribution of values:

	partNum		= 1	swap	4MiB	8GiB	HIBERNATE	none
	partFsType	= 
	partStart	= 
	partEnd		= 
	partName	= 
	partMount	= 
	partNum		= 2	swap	8GiB	12GiB	BOOT		/boot
	partFsType	= 
	partStart	= 
	partEnd		= 
	partName	= 
	partMount	= 
	partNum		= 3	ext4	12GiB	200GiB	DB007_F1	/
	partFsType	= 
	partStart	= 
	partEnd		= 
	partName	= 
	partMount	= 
	partNum		= 4	ext4	200GiB	100%	DB007_F2	/DB007_F2
	partFsType	= 
	partStart	= 
	partEnd		= 
	partName	= 
	partMount	= 
1 Like

You’ve set IFS to :, but : is not the delimiter in the input.

3 Likes

Hi, @stevemowbray and welcome to the Ubuntu MATE Community!

Duh!!! I am so dense! Sorry for bothering. Now that you point it out, it is SO obvious. I was too focused on my specification line, rather than the actual data.

Thank you very much!

:slight_smile:

2 Likes