Bash Script - wallpaper organizer

syntax error near unexpected token `else'

Page 1 of 1

4 Replies - 1264 Views - Last Post: 11 November 2010 - 12:53 PM Rate Topic: -----

#1 vzybilly  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 160
  • Joined: 24-September 08

Bash Script - wallpaper organizer

Posted 10 November 2010 - 11:16 PM

Well, I'm not sure what the issue is here but the program is located in /new_walls which holds about 500 images right now, the code is:
#!/bin/bash
# Move wallpapers to wallpaper folder while removing spaces.

ONE=1  # For getting singular/plural right (see below).
number=0  # Keeps track of how many files actually renamed.
FOUND=0  # Successful return value.

for filename in *  #Traverse all files in directory.
do
	if [ "$filename" = "000_Proccess_New_Walls" ]  #Watch out for this program
	then
		ONEZY=1
	else
		if [ "$filename" = "000_Proccess_New_Walls~" ]  #Watch out for this program
		then
			ONEZYZY=1
		else
			echo "$filename" | grep -q " "  #  Check whether filename
			if [ $? -eq $FOUND ]  #+ contains space(s).
			then
				fname=$filename  # Yes, this filename needs work.
				newlocation=`echo $fname | sed -e "s/ /_/g"`  # Substitute underscore for blank.
			else
				newlocation=$filename
			fi
			width=`identify -format '%w' $filename`  #get image width
			height=`identify -format '%h' $filename`  #get image height
			if [ $height -ge 700 ] then  #is in first standard?
				if [ $width -ge 1000 ] then  #is in last standard?
					let "number += 1"  #we are proccesing a file
					mv "$filename" "../walls/$newlocation"  #move it
					echo "Image moved successfully  : $filename"  #output of success
				else  #whats wrong here?
					echo "Standards not met in Image: $filename"  #no like
				fi
			else
				echo "Standards not met in Image: $filename"  #no like
			fi
		fi
	fi
done   


if [ "$number" -eq "$ONE" ]                 # For correct grammar.
then
	echo "$number file moved."
else 
	echo "$number files moved."
fi 

read -p "Files remaining did not meet standards. done." d  #just to see what the output was...
exit 0

and output is:
vzybilly@computer:/new_walls$ ./000_Proccess_New_Walls
./000_Proccess_New_Walls: line 33: syntax error near unexpected token `else'
./000_Proccess_New_Walls: line 33: `				else  #whats wrong here?'



I can't see anything wrong here but I've only recently started with bash...

Is This A Good Question/Topic? 0
  • +

Replies To: Bash Script - wallpaper organizer

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5319
  • View blog
  • Posts: 27,227
  • Joined: 10-May 07

Re: Bash Script - wallpaper organizer

Posted 10 November 2010 - 11:51 PM

I don't know if this will fix the error, but your if statements should have a semi-colon if you use than & if on the same line :

			if [ $height -ge 700 ]; then  #is in first standard?
				if [ $width -ge 1000 ]; then  #is in last standard?
					let "number += 1"  #we are proccesing a file
					mv "$filename" "../walls/$newlocation"  #move it
					echo "Image moved successfully  : $filename"  #output of success
				else  #whats wrong here?
					echo "Standards not met in Image: $filename"  #no like
				fi
			else
				echo "Standards not met in Image: $filename"  #no like
			fi



You'll notice that line 33 is the 1st else that is for an if that has a than on the same line ;)
Was This Post Helpful? 1
  • +
  • -

#3 vzybilly  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 160
  • Joined: 24-September 08

Re: Bash Script - wallpaper organizer

Posted 11 November 2010 - 08:13 AM

That worked... whats the difference between the then being on the next line or the same line?
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5319
  • View blog
  • Posts: 27,227
  • Joined: 10-May 07

Re: Bash Script - wallpaper organizer

Posted 11 November 2010 - 12:18 PM

They are actually two commands.

You can verify this at the command line with the following :

ls; clear; echo "Screen is clear..."


You should only see screen is clear displayed on your screen.

Follow that up with the following :

ls
clear
echo "Screen is clear"


& the situation is the same. if & than are technically two different commands. So you must tell the shell where the if stops & than begins, or put them on two different lines.
Was This Post Helpful? 0
  • +
  • -

#5 vzybilly  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 160
  • Joined: 24-September 08

Re: Bash Script - wallpaper organizer

Posted 11 November 2010 - 12:53 PM

thanks, I didn't know that. like I said, I'm just starting with bash ^^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1