String with different length

let image that we have string:
QQQQQQQ:ABCDE:FFFFFF:GGGGG

in second field can be 0 or 5 characters

if A exist i need set variable ex: VAR=yes
if B exist i need set variable ex: VAR1=yes
if C exist i need set variable ex: VAR2=yes
etc ...
if second field is empty no variable to set
if in second field exist A and C only i need set VAR & VAR2 no others

can anybody help with that?

Something like this?

#!/bin/ksh

str="QQQQQQQ:ABDE:FFFFFF:GGGGG"

set $(echo $str | tr ':' ' ')

if [[ $2 =~ "A" ]]
then
  VAR=yes
fi

if [[ $2 =~ "B" ]]
then 
  VAR1=yes
fi

if [[ $2 =~ "C" ]]
then 
  VAR2=yes
fi

Why did you use [[...]] instead of [...]

if [[ $2 =~ "C" ]]
if [ $2 =~ "C" ]

# str="QQQQQQQ:ABDE:FFFFFF:GGGGG"
# set $(echo $str | tr ':' ' ')
# [[ $2 =~ "A" ]] && echo yes
/usr/bin/ksh: 0403-057 Syntax error: `=~' is not expected.

I got this error :frowning:

i trying do this on AIX - ksh (Version M-11/16/88f)

---------- Post updated at 09:44 AM ---------- Previous update was at 08:47 AM ----------

Ok i solved problem:

With the test command [[...]] you can use extended regular expressions like [[ $2 =~ "A" ]].

The test command [[..]] with an ERE works with ksh93 not with ksh88.