A ( too many?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A ( too many?
# 1  
Old 07-06-2012
A ( too many?

Anyone able to assist with the following:

Code:
#!/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:

Code:
/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

Moderator's Comments:
Mod Comment Please view this link: How to use [code]...[/code] tags

Last edited by Scrutinizer; 07-06-2012 at 05:14 AM.. Reason: code tags
# 2  
Old 07-06-2012
You would need ksh93 (not ksh88) for these extended pattern lists, and I suspect the spaces should not be there:
Code:
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?
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 07-06-2012
Scrutinizer - Solaris 10...

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

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

Thanks
# 4  
Old 07-06-2012
That's what the #! is for...
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question