Register
It is currently Sat Apr 19, 2014 11:45 pm

Not sure of proper if syntax, getting an error


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Wed Nov 05, 2008 9:05 pm   

Joined: Wed Nov 05, 2008 1:43 pm
Posts: 3
Location: Cottage Grove, Oregon
Hello,

I have a script I've written that works on my machine but when ran on a friend of mine's system tosses an error about one of my if statements. Here's the code I'm using


Code:
if [ -e /usr/bin/apt-show-versions ]
   then touch ~/SysReport/versions.txt
      chmod 777 ~/SysReport/versions.txt
      apt-show-versions > ~/SysReport/versions.txt
      echo "     Sorting version list"
      sort ~/SysReport/versions.txt >> ~/SysReport/software.html;

   else echo "apt-show-versions not found, follow directions above to get this output" >> ~/SysReport/software.html;
fi


Here is the error message it generates

Code:
adminmandi@Ub-desktop:~/Desktop$ sh SystemReport.sh
Creating SysReport Folder
SystemReport.sh: 686: Syntax error: "else" unexpected (expecting "fi")


Should I be using semi-colons after all statements in the then portion of the if?

Thanks for any help you can be.

Later, Ray Parrish[/code]


Top
 Profile WWW  
 PostPosted: Thu Nov 06, 2008 12:13 pm   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Hmm... I don't think you need those semicolons there, but I'm not sure that's going to cause that particular error. Try formatting it like this:

Code:
if [ -e "/usr/bin/apt-show-versions" ]; then
  touch ~/SysReport/versions.txt
  chmod 777 ~/SysReport/versions.txt
  apt-show-versions > ~/SysReport/versions.txt
  echo "     Sorting version list"
  sort ~/SysReport/versions.txt >> ~/SysReport/software.html
else
  echo "apt-show-versions not found, follow directions above to get this output" >> ~/SysReport/software.html
fi


I'll test this on my deb box in a sec :)

-J


Top
 Profile YIM  
 PostPosted: Thu Nov 06, 2008 1:18 pm   

Joined: Wed Nov 05, 2008 1:43 pm
Posts: 3
Location: Cottage Grove, Oregon
Hello,

Well, I tried that in my script, and once again it tosses no errors on my machine. The acid test will be when I have my friend try to run it on her machine, where the error cropped up.

I tried it with absolutely no semi-colons, a semi-colon after the then list, and semi-colons after all statements in the if, and none of those variations has caused an error for me on my machine. Very strange....

Later, Ray Parrish



Top
 Profile WWW  
 PostPosted: Thu Nov 06, 2008 6:20 pm   

Joined: Wed Sep 24, 2008 11:32 pm
Posts: 7
What's your first line of the script? I mean, if it is "#!/bin/sh", then maybe it works differently on machines with different default shell.


Top
 Profile  
 PostPosted: Thu Nov 06, 2008 6:40 pm   

Joined: Wed Nov 05, 2008 1:43 pm
Posts: 3
Location: Cottage Grove, Oregon
Hello again,

Well we finally figured out what was going on. FileZilla was hosing the script when I uploaded it to my server.

My friend was able to open the script with Kwrite and use it to set the line endings in it to Unix style and it would run for her. I thought this was odd as I had already done that before uploading the script.

So, I put the script in a .tar.gz archive and uploaded it again, and this time it worked with no errors!

So... it wasn't syntax that was the problem, it was being corrupted somehow during the upload even 'though I set it explicitly to asciii mode of transfer.I wonder if that's because my web hosting is on a windows server?

Just so you know, the first line of the file is #!/usr/bin/env bash which is supposed to locate bash if it isn't in the normal place.

Later, Ray Parrish
:)


Top
 Profile WWW  
 PostPosted: Fri Nov 07, 2008 11:18 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 242
Ha!

I hate it when that happens. If your friend doesn't have it already, there's a command line utility called "dos2unix" that fixes that as well. In Debian it gets installed with the sysutils package, in a package called "tofrodos"

Have fun!
-J


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP