string extraction won't work. Why?

#!/usr/bin/ksh
set -x
testfile=my.test.file.flag
echo ${testfile: (-4)}
#/home/maldohe/scripts/spawn1&
sleep 3
echo myspawn is now ending
exit

Background:
I am trying to extract the word flag from anf given file name. This is a demo script that I am working on to fix a production issue. We get FTP files from various place and each come with a "FLAG" file once the data file is received. I am want to trap for the "FLAG" file and do something with it before it gets processesd.

Thanks in advance

I'm not sure I understand completely.

Do you want the filename minus ".flag"? If so:

#! /usr/bin/ksh

testfile=my.test.file.flag
printf '%s\n' "${testfile%.flag}"
echo ${testfile%%.flag}

I am guessing you want to remove the .flag part from the filename.
This is called parameter substitution, you can look up the rest of the operator for this online or in your man page

Actually, I am reviewing all files received and the files with the word "FLAG" as part of the filename I need to suspend for a time. Normally, the word "FLAG" comes at the end of the file name.

You need to be very clear here.

What do you mean by "suspending" based on a file? What exactly do you want to do?

Sorry, if my script find a file with the word "FLAG" in the name, I am going to move that file to a new location so that it does not get picked up by another deamon process until a later time.

---------- Post updated at 11:10 PM ---------- Previous update was at 11:05 PM ----------

If the initial script that I posted could work I could test for the existance for the word "FLAG" or at least test the return code $? i think.

OK, how about:

#! /usr/bin/ksh

for file in *; do
	if [[ "${file:(-4)}" == "flag" ]]; then
		# Do some processing here. Maybe:
		/bin/mv "$file" /tmp/
	else
		# Do something else. Maybe nothing.
		:
	fi
done

If that more of what you were looking for?

Thanks so much for your help. I reviewed the script I posted and found that the script will not work in ksh but works fine in bash.

Your script looks like it will do exactly what I need also. I'll give it a shot. Thanks again.

---------- Post updated at 11:17 PM ---------- Previous update was at 11:14 PM ----------

It would be cool do analyze the full file name for the word "FLAG" just in case it's not the last part of the file name.

Easy enough.

#! /bin/bash

filename=my.test.file.flag
if [[ "$filename" =~ "flag" ]]; then
	printf '%s\n' "Matched flag"
fi