Since you mention using <<<
, I'll assume you are using a shell that supports arrays (specifically, bash
. Other shells--notably zsh
--may use different syntax for what I am about to describe).
images=( *.img ) # No need to parse ls, which is generally a bad idea
Assuming there is only one matching file, you can then use
disk=${images%.img}
to strip .img
from the file name and save the remaining portion in disk
. If there could be multiple matches, you can apply the extension stripping to each element of the array and store the result in a second array.
disks=( "${images[@]%.img}" )