syntax error: `$' unexpected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting syntax error: `$' unexpected
# 1  
Old 06-07-2010
syntax error: `$' unexpected

Hi all,
Am very new to Unix and am currently Involved in Migrating some Shell Scripts from AIX 4 to Solaris 10.

While using teh for loop am getting the below error:
Code:
$ echo $SHELL
/usr/bin/ksh
$ for file in $(ls *SEBE*)
syntax error: `$' unexpected

while the same works without issue on AIX.

Please Help!!!

Last edited by vbe; 06-07-2010 at 01:10 PM.. Reason: code tags please
# 2  
Old 06-07-2010
well, try to switch to bash/sh, on my test Solaris 9 system, that construct works well; and don`t forget, that you`ll need to expand your script to something like this:

Code:
for file in $(ls -la) ; do echo $file; done


Last edited by vbe; 06-07-2010 at 01:16 PM.. Reason: plain english...
# 3  
Old 06-07-2010
Tried Switching, but does not work
Code:
$ echo $SHELL
/usr/bin/ksh
$ SHELL=/bin/sh
$ echo $SHELL
/bin/sh
$ for file in $(ls -la)
syntax error: `$' unexpected
$

Read a Post that kron shell does not support $(COMMAND) and must use `COMMAND`
tried that way and it works.
But i was expecting that if i am Adding the line
Code:
#!/bin/ksh
as the first line in my Script, it should work.
So My Script
#!/bin/ksh
  
set -a
  
for file in $(ls *SEBE*)
do
  tfile=$(basename $file)
  echo "File name is $tfile"
done
set +a

must ideally work, But does not and i have to change it to:
Code:
#!/bin/ksh     # Set Korn Shell Environment

for file in `ls *SEBE*`
do
  #
  # Get the file name to process.
  #
  tfile=`basename "$file"`
  echo $tfile
done

Experts Does teh above make any Sense?

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scott; 06-07-2010 at 03:58 PM.. Reason: Code tags, PLEASE!
# 4  
Old 06-07-2010
If it works, it works. Solaris tends to have very old nonposix shells for compatibility reasons, though I'd previously believed at least ksh was relatively modern...
# 5  
Old 06-07-2010
First of all I'd like to say, that AFAIK simply setting the SHELL variable does not actually change the current shell.
Code:
[myuser@myhost /]$ echo $0
bash
[myuser@myhost /]$ echo $SHELL
/usr/local/bin/ksh93
[myuser@myhost /]$ SHELL=/bin/sh
[myuser@myhost /]$ echo $SHELL
/bin/sh
[myuser@myhost /]$ echo $0
bash
[myuser@myhost /]$ /bin/sh
$ echo $0
/bin/sh
$

Second: AFAIK it's not a good idea to use ls in that manner, why not simply try following:
Code:
for file in *SEBE*

Third: IMHO that basename part it completely unnecessary in this case.

Last edited by pseudocoder; 06-07-2010 at 04:02 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error: `]' unexpected

I am getting this error Syntax error: `]' unexpected. Did I do something wrong with elif? Does ksh not like double brackets? if ]; then #echo hi source ~/.bashrc; elif ]; then #echo hi source ~/.kshrc; fi (5 Replies)
Discussion started by: cokedude
5 Replies

2. UNIX for Beginners Questions & Answers

Syntax error near unexpected token

Dears, While executing the below script im getting the error at line 30. Please let me know what changes to be done to fix this. test.sh: line 30: syntax error near unexpected token `done' test.sh: line 30: ` done ' #!/bin/sh # Rev. PA1 # author: eillops # date: 26-04-2018 # #... (1 Reply)
Discussion started by: Kamesh G
1 Replies

3. Shell Programming and Scripting

Syntax error `(' unexpected

I have written this in my script but while running i am getting syntax error `(' unexpected. unload to "$BACKUP_DIR/n_fac_fid-$clliname" select * from n_fac_fid where fac_accesskey in (select fac_accesskey From n_fac_ap_fid where ap_clli="$clliname"); Any help appreciated. (3 Replies)
Discussion started by: suryanmi
3 Replies

4. Shell Programming and Scripting

Syntax error: 'fi' unexpected

unzip file.zip if ] ; then echo "Success" else echo "Some failure." fi ; I tried many time to detect the unzip error, but it keep show the syntax error wherever how I change the syntac. Hope someone can help me fix the issue, thanks. Please use code tags next time for your code and... (5 Replies)
Discussion started by: duncanyy
5 Replies

5. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

6. Shell Programming and Scripting

Syntax error near unexpected token `}' please help

I'm going mad not being able to get this to work. im assuming its only a simple mistake but its driving me bonkers trying to find it. Please if you can help me it would save me pulling my hair out!! Thanks #!/bin/bash -xv # #Config name="TEST Server" + name='TEST Server'... (6 Replies)
Discussion started by: Fisheh
6 Replies

7. UNIX for Advanced & Expert Users

syntax error near unexpected token '{

Hi, I am running the following script through cygwin and getting below mentioned error. ******************************************* #!/bin/sh # constants WORK_DIR="deploy" INFOFILE="deploy.info" INTROFILE="Intro.sh" CMGMT_PKG="com.kintana.cmgmt.deploy" DEPLOY_PREFIX="mitg" ... (2 Replies)
Discussion started by: MandyR
2 Replies

8. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies

9. Shell Programming and Scripting

unexpected syntax error

Hi, i am getting following syntax error ...kingly advice why is it coming ?? #!/bin/bash find . -name "common.log" if ; then echo "1" fi Himnashu@home /bin $ ./a.sh ./a.sh: line 7: syntax error near unexpected token `fi' ./a.sh: line 7: `fi' (9 Replies)
Discussion started by: himvat
9 Replies

10. Shell Programming and Scripting

sh: syntax error: `...' unexpected???

Hello all, I want to create a script that polls every hour a directory for the existence of a file. The file I look for is a `token` dropped by an external process at the completion of a successful FTP process. I wrote this script `checkfile.ksh`: #!/usr/bin/ksh if ] then mailx... (5 Replies)
Discussion started by: alan
5 Replies
Login or Register to Ask a Question