Rename error message!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename error message!
# 1  
Old 04-22-2004
Rename error message!

Can anyone tell me why I keep on getting this error message?

../dosRename: syntax error at line 77: `end of file' unexpected

I have treid everything and I just can get it to work!
Here is the code:

#!/bin/sh

Usage() {
[ $# -ne 0 ] && echo "\n$*\n" >&2
cat <<-EOD_USAGE >&2
Usage: $0 file... target
file... List of files to rename
target Target name

EOD_USAGE
exit 1
}


# Get and verify arguments


# Argument count

[ $# -lt 2 ] && Usage "Missing arguments."

# Files to rename

while [ $# -gt 1 ]
do
file=$1
case "$file" in
*.*.*|*\**) Usage "Invalid file name : $file" ;;
esac
[ -e "$file" ] || Usage "File not found : $file"
file_list="$file_list $file"
shift
done

# Target name

target=$1
case "$target" in
*.*.*|*\**\**) Usage "Invalid target name : $file" ;;
esac
target_nam=`echo "$target" | cut -d. -f1`
target_ext=`echo "$target" | cut -d. -f2`


# Rename loop


for file in $file_list
do
# Actual file name and extension

file_nam=`echo "$file" | cut -d. -f1`
file_ext=`echo "$file" | cut -d. -f2`

# New file name and extension

if [ "$target_nam" = '*' ]
then new_nam="$file_nam"
else new_nam="$target_nam"
fi
if [ "$target_ext" = '*' ]
then new_ext="$file_ext"
else new_ext="$target_ext"
fi
[ -n "$file_ext" ] && file_ext=".$file_ext"
[ -n "$new_ext" ] && new_ext=".$new_ext"
new="${new_nam}${new_ext}"

# Rename

echo "Rename file $file to $new ..."
if [ -e "$new" ]
then echo "Not renamed, target file already exists : $new" >&2
else mv "$file" "$new"
fi
done

Many thanks.
# 2  
Old 04-22-2004
I've copied/pasted your code on a RH9-box and it worked fine.
Try adding an extra linefeed to the end of the file though, I've seen this before.

Hope it helps !

Bart.
# 3  
Old 04-22-2004
Zeta_Acosta, I answered this question in this post. You will continue to have problems until you follow my advice.

Bart, to reproduce this error you must do two things. If you use our quote function on the first post in this thread, you will see the white space characters that get deleted since Zeta_Acosta did not use code tags. Notice that the line "EOD_USAGE" has some leading white space. So type some spaces or tabs in front of the capital E. And switch to the old bourne shell which cannot tolerate this situation. Now the script will fail for you too.

Zeta_Acosta, one more time, all you need to do is make the capital E be the very first character on the line. No leading spaces or tabs. No trailing spaces or tabs. Nothing at all on the line except EOD_USAGE. Give it a try.

And if you will not try this, do not open a third thread to post the same question again. Instead, post the question again in one of your pre-existing threads. That will save some time. Smilie
# 4  
Old 04-22-2004
You are correct, Perderabo. I have used the quote function and am now able to reproduce the error.

The white-space in front of EOD... is indeed the culprit.
# 5  
Old 04-22-2004
I strike again, Im sorry pederabo! I should have looked at the previous posts.

Did I ever tell you that YOUR GREAT!

Thanks again every1!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

File rename error

hi im new for unix, when i try to rename the file im getting error $ mv -9file.jpg 9file.jpg error is mv: invalid option --"9" Try 'mv --help' for more information. (10 Replies)
Discussion started by: gwgreen1
10 Replies

2. Shell Programming and Scripting

Perl script to rename file,error

#!/usr/bin/perl $FL="ch.txt"; $CFL="mytext.txt"; print "This script will rename textfiles."; mv $FL $CFL; print "Done."; perl file.pl Error: Can't locate object method "mv" via package "ch.txt" (perhaps you forgot to load "ch.txt"?) at file.pl line 7. (5 Replies)
Discussion started by: cola
5 Replies

3. UNIX for Dummies Questions & Answers

Error Message

I am getting a error message when I try to assign this? Can someone help I am new to unix? $ First-name=james ksh:First-Name=james not found (1 Reply)
Discussion started by: vthokiefan
1 Replies

4. UNIX for Dummies Questions & Answers

What does this Error Message Mean

Hi I found the following error message in my logs: warning: /etc/hosts.deny, line 6: can't verify hostname: getaddrinfo(localhost) didn't return ::ffff:222.255.28.33 What is the error message trying to indicate? That there is a problem with line 6 (2 Replies)
Discussion started by: mojoman
2 Replies

5. UNIX for Dummies Questions & Answers

Error Message

I keep getting an error message in a script im writing, this line is allways pointed out. if and this is the message i keep getting. line 32: [: 8: unary operator expected Whats wrong with it? Please Help. (5 Replies)
Discussion started by: chapmana
5 Replies

6. Shell Programming and Scripting

Error message

I am new to scripting. I am using the following script . BART.dat contains the string 'Y' . #!/bin/ksh cd /work/TCI/data_out file=`cat BART.dat` echo "$file" if ; then echo "true" fi When i am executing the above script i am getting the following error ./s.ksh: : not found ... (2 Replies)
Discussion started by: ammu
2 Replies

7. UNIX for Dummies Questions & Answers

getting last error message

Question for unix programmers - what function I need to used to get the exact error message when the library failed to load? Thanks (1 Reply)
Discussion started by: tttttt
1 Replies

8. UNIX for Advanced & Expert Users

error message

I get this error message as soon as i log in -bash: /usr/local/software/.../vni/CTT6.0/ctt/bin/lopt64.sh: No such file or directory I looked into the etc/profile but there are no lines sourcing this file. And there is no lopt64.sh in the directory vni/.../bin I couldn't fogure out what... (4 Replies)
Discussion started by: dsmv
4 Replies

9. Solaris

lp error message

Both of these messages are filling up the /var/adm/messages files on these two Sun boxes, goober and gomer. The print server is called gold. Jul 31 03:15:40 gold bsd-gw: request to ma28084.Solaris (unknown printer) from goober Jul 31 03:16:39 gold bsd-gw: request to ma28084.Solaris (unknown... (1 Reply)
Discussion started by: antalexi
1 Replies

10. UNIX for Advanced & Expert Users

Error message

I'm getting an error - symbol referencing errors. No output written to, etc Can anybody tell me why this is? (2 Replies)
Discussion started by: Dan Rooney
2 Replies
Login or Register to Ask a Question