LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-10-2010, 02:38 PM   #1
SentralOrigin
Member
 
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318

Rep: Reputation: 30
ksh syntax error: `(' unexpected


So I am trying to convert my bash script into ksh, and this is what I have in the file so far:

Code:
#!/bin/ksh

login()
{
        if [ "$ALPHA" = "" ]
        then
sendcmd BETA
else
sendcmd "$(xxd -c 32 -g 0 ${ZETA_ZETA} | awk '{print $2}')"
        fi
}
But when I run it:
Code:
$ ./test.sh  
./test.sh[3]: syntax error: `(' unexpected
Am I not seeing something here? I closed all of my () and I don't see any open parentheses...
 
Old 11-10-2010, 02:42 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
You need a space between login and () where you define the function.

Also note, if it matters in your code, that in ksh, there is a difference in the way a function works, depending whether or not you define it using the function keyword before the function name. You can see something about this here:
http://www.linuxquestions.org/questi...erence-825846/
 
Old 11-10-2010, 02:46 PM   #3
SentralOrigin
Member
 
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318

Original Poster
Rep: Reputation: 30
Space doesn't help.

I added in some more functions before this line, and there is no problem with them:

Code:
#!/bin/ksh

usage()
{
cat <<EOF

$VERSION

usage: test [-switches] [variables]

EOF
exit 2
}

sendcmd()
{
        echo "$@"
        sleep ${SLEEP_AFTER_CMD}
}

login()
{
        if [ "$ALPHA" = "" ]
        then
sendcmd BETA
else
sendcmd "$(xxd -c 32 -g 0 ${ZETA_ZETA} | awk '{print $2}')"
        fi
}
Code:
$ ./test.sh         
./test.sh[22]: syntax error: `(' unexpected
Still only complains about login()...???
 
Old 11-10-2010, 02:48 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556


Umm, I think `login` is a keyword or command (I just ran it, and am not sure what it's doing.. EDIT: It's started a login shell in my terminal :/ ) Try using another word?
 
1 members found this post helpful.
Old 11-10-2010, 02:54 PM   #5
SentralOrigin
Member
 
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318

Original Poster
Rep: Reputation: 30
Thanks...I have to smack myself now
 
Old 11-10-2010, 02:57 PM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Ehh... Probably most of us have or will encounter this sort of glitch at some point.

Good luck with the rest of the script porting. :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error near unexpected token jchmski Programming 5 06-18-2010 10:28 AM
syntax error near unexpected token `then' snakernetb Linux - Server 4 02-16-2010 06:40 PM
Syntax error near unexpected token :( please help mikejosh Programming 4 01-29-2010 06:54 AM
syntax error near unexpected token `else' alex0 Programming 7 07-28-2009 08:01 AM
why am getting error ksh: syntax error: `fi' unexpected while running script deb4you Linux - Newbie 4 09-06-2008 08:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration