A ( too many?

Anyone able to assist with the following:

#!/bin/ksh

-- snip --

echo "\n\nEnter number associated with the change: \c"
                read inc_num
                if [[ "$inc_num" = ? ([+-]) + ([0-9]) ]] || [[ $inc_num = S ]] || [[ $inc_num = s ]]
                then

-- snip --

Above code used to ensure that only a numerical value (or an S) is entered for inc_num, but unfortunately it's bombing out at the following:

/rsl_v2: line 35: syntax error in conditional expression: unexpected token `('
./rsl_v2: line 35: syntax error near `(['
./rsl_v2: line 35: `                if [[ "$inc_num" = ? ([+-]) + ([0-9]) ]] || [[ $inc_num = S ]] || [[ $inc_num = s ]]'

Not sure whether it's a genuine syntax error, cause I've tested this on another system and it works fine - could it be the version of ksh maybe?

Thanks in advance.
CiCa

You would need ksh93 (not ksh88) for these extended pattern lists, and I suspect the spaces should not be there:

if [[ "$inc_num" == ?([+-])+([0-9]) ]] || [[ $inc_num == S ]] || [[ $inc_num == s ]]

You could give that a try.. Also the correct syntax is a double ==

What is your OS and version?

1 Like

Scrutinizer - Solaris 10...

Just had an idea and changing to ksh (and not bash) allows the script to run without issue - yay! :slight_smile:

Although - do you know if there is a way to automatically change to shell ksh within the script?

Thanks

That's what the #! is for...