I can't seem to figure out how I can put a fdisk command from a bash script in a multiline variable.
Here is my code
hdds="$(sudo fdisk -l | grep "Disk /dev/sd" | awk '{print$2}' | sed 's/://g')"
When I execute this bash script it puts everything on a single line like
/dev/sda /dev/sdb
When I execute this command outside of the bash script it works like it should
sudo fdisk -l | grep "Disk /dev/sd" | awk '{print$2}' | sed 's/://g' | wc -l
Where the output is 2
.
I have tried putting everything in quotes, without quotes and what not but nothing seems to work.