1

I wrote a shell script that does data manipulation on a server running bash shell.

My script has a function which retrieves data inside ZIP files

function getCTLfile() {
  for i in ${Array[@]}; do 
    if [[ `echo ${i}|awk -F . '{print $NF}'` == "ctl" ]]; then 
      echo "${i}" 
    fi
  done
}

It works great but this machine hardware is faulty so our sysadmin requested that I port my code to another server running Korn shell.

When I run my script, it fails on my function!! Even if I type it from the command line.

$ function getCTLfile() {
-ksh: syntax error: `(' unexpected

Do I need to change my syntax anywhere? I did some research and it seems that everything should work.

2
  • 1
    code review: if [[ "$i" == *.ctl ]] is much clearer. You almost certainly want to quote "${Array[@]}" Commented Aug 29, 2013 at 19:45
  • 2
    case $i in *.ctl) echo "$i";; esac is a lot simpler, portable, and idiomatic. Commented Aug 29, 2013 at 19:59

1 Answer 1

6

The function declaration syntax in ksh either uses the function keyword or the parentheses, but not both. Leave out either the parentheses or the function keyword and it should work.

Sign up to request clarification or add additional context in comments.

2 Comments

Damn. I did not pay attention to that little detail. Bingo. Accepted and voted up. I was going nuts! Thank you!!!
@Chris: By the way, please note there are differences in functionality between the two syntaxes in ksh93, specifically with the scope of declared (typeset) variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.