Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-01-2008, 01:31 AM   #1
LQ Newbie
Registered: Sep 2008
Posts: 18

Rep: Reputation: 0
Problem with if statement in a find -exec statement

Ok I have been doing as much research as google will allow. I have found similar problems but haven't been able to find a solution. I'm sure it is just me being dumb.

<code>$ bash --version
GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, to the extent permitted by law.

$ find --version
GNU find version 4.2.31
Built using GNU gnulib version 2007-02-24

I have a directory with a number of subdirectories and files that the names were all messed up while I was playing with sed. (Yes it was my fault) I'm also just playing around with one liners and scripts. Long story short is I was playing with sed and find to remove spaces and special characters and issued a command that was something like this

<code>$ find Music/ -name "*" -exec sh -c 'n=$(echo "$1" | sed "s/ /_/g"); mv -v "$1" "$n" 2>&1 newsuccess.txt' sh '{}' \;</code>

Now most of the directories and files are missing letters in the name. So I started trying to figure out how make it prompt me and ask me to rename the file but since I don't know how deep the directory structure goes and I don't know what letters are missing. So this is what I can up with:

<code>$ find Music/ -name "*" -exec sh -c 'echo "$1" ; echo "What do you want to rename this too: " ; read newname ; if [ "$newname" != "no" ]; then mv -v $1 $newname else echo "Skipping..." fi' sh '{}' \;</code>

But when I execute it i get:

sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 1: syntax error: unexpected end of file

I can't figure it out but if anyone can help or maybe suggest something better I would be most grateful.
Old 10-01-2008, 02:06 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Put a semicolon ( ; ) before else and fi.
(may need space after the semicolon, I'm not sure)
Old 10-02-2008, 12:38 AM   #3
LQ Newbie
Registered: Sep 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Thank you

Thank you very much that resolved it. But unfortunately it appears that I have become the victim of the Synaptic touch pad issue. I have done a boat load of research and can seem to figure it out. But now I'm not sure if it is my xorg.conf or if it just died. Tried it on a live cd and it didnt work their either.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Problem in Writing IF statement p_raju Linux - General 2 06-06-2008 04:06 AM
find statement tostay2003 Programming 4 12-11-2007 11:44 AM
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 08:05 PM
Problem with unix if statement abefroman Programming 3 07-30-2005 04:24 PM
Python EXEC Statement ranger_nemo Programming 3 07-24-2003 08:31 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:05 PM.

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