Bash substring expansion on array
I have a set of files with a given suffix. For instance, I have a set of pdf files with suffix .pdf . I would like to obtain the names of the files without the suffix using substring expansion. For a single file I can use: file="test.pdf" echo ${file:0 -4} To do this operation for all files, I now tried: files=( $(ls *.pdf) ) ff=( "${files[@]:0: -4}" ) echo ${ff[@]} I now get an error saying that substring expression < 0 .. ( I would like to avoid using a for loop ) Use parameter expansions to remove the .pdf part like so: shopt -s nullglob files=( *.pdf ) echo "${files[@]%.pdf}" The shopt -s