separating filename and extension

Hi (warning: newbie question),
I am writing a script to run a series of tests on a program, which involves a line:

for file in `ls test_suite/*.args`

but later I want to send the output to file.out. But I need to separate the filename and extension somehow...Also $file contains "test_suite/" before each entry as well, how do I get rid of that (I assume it's in a similar way as the separation above)

Thanks!

HI,
You can get the filename alone excluding the directory using following command
for file in `ls test_suite/*.args`
do
F_NAME=$(basename ${file})
done

Thanks
Raghu

1 Like
for f in test_suite/*.args;do 
	fn="${f%.*}" 
	printf "filename without path and extension: %s, extension only: %s\n" "${fn##*/}" "${f##*.}"  
done

With bash you can do something like this (if I understand correctly the requirement):

set test_suite/*.args
set "${@##*/}"
printf "%s\n" "${@%.*}">file.out