Unix bash script (mv issues);


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix bash script (mv issues);
# 1  
Old 04-24-2012
Unix bash script (mv issues);

Hey guys,

I've registered here as I need urgent help. This is assignment for school and as you can see below I've completed the work. I'm simply stuck on one area.

Smilie

This script takes the first parameter (which is to be the new extension) and each parameter after that is a file name (which will have its old extension turned into the new one). Mind you, this script works almost perfectly.

The test script (the one that grades my assignment) forces this line to call the script running from the "filderFilesAreIn" directory:
Code:
./theScriptName.sh 'dat' 'file1.txt' 'file2.cpp' 'file3.dat' '../folderFilesAreIn/file4.dat'

My script does the first 3 files flawlessly. The 4th file, though, my code produces this output:
Code:
mv: `../folderFilesAreIn/file4.dat' and `../folderFilesAreIn/file4.dat' are the same file

It's strange as even though 'file3.dat' already exists, it replaces it with no error like above. The directory path before 'file4.dat' seem to cause the "mv -f" command to act differently.

In my code, I've used "mv -f" which is supposed to force the command to overwrite the file. This error isn't causing the program to not work but the test script (the one that grades the assignment for pass/fail) isn't letting me pass as this output is "unexpected" by it. This message is causing the script to think my code doesn't work because of the extra output.

Any help would be appreciated! I can't seem to find a way to cause "mv" to not produce any output. If I could silence the output or use another command to replace the file without getting any extra output it should count.

Thanks for your help! It's very frustrating and the teacher is being no help.

My full code is below (it's obviously not the best, but it's for a 1 credit class)
http://codeviewer.org/view/code:254d
# 2  
Old 04-25-2012
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash/cron issues

Hi all, I am trying to run a cronjob to push my files to my git repo once a week and output a prompt to a logfile, my script works fine if I invoke it manually but my cronjob wont run for some reason, I have sourced the file, and restarted my Mac to no avail, right now I believe I have the cronjob... (8 Replies)
Discussion started by: gmenfan83
8 Replies

2. Shell Programming and Scripting

Bash Case Issues..

Hi, I'm having some trouble with using "case...esac" in Bash. I've googled it and am stuggling to understand the syntax and how to do certain things. Firstly, I want to be able to choose a case based on a variable number For example, I have in my code a place where a user can enter... (2 Replies)
Discussion started by: Ste_Moore01
2 Replies

3. Shell Programming and Scripting

Bash Script Issues (If statement for file copying)

Writing a bash script for use with Geektool, pulls the battery info, and shuffles images around so that an Image geeklet can display the correct expression as the desktop background. (Eventually I intend to make it more intricate, based on more variables, and add more expressions) I'm extremely... (1 Reply)
Discussion started by: The_Ardly374
1 Replies

4. Shell Programming and Scripting

Issues for script that login to a unix box

Hi, I have a script that should login to a different box then the box that i am in and run the commands. I have the script sample below that logins to a unix box and get the files .Looks like ls-lrt command is not running or its wrongly used. #!/bin/bash # Ask the user for build month... (5 Replies)
Discussion started by: learninguser235
5 Replies

5. Shell Programming and Scripting

Bash: renaming file issues.

Hi, i want to rename a group of directories and files of my music, some items are like this: - , for directories. - , for files. I want to do something like this: , for directories. , for files. This is my code: #!/bin/bash for fname in *.mp3; do echo item: $fname mv... (2 Replies)
Discussion started by: josco1982
2 Replies

6. Shell Programming and Scripting

Bash Script issues

So what i am trying to do is write a script that takes in any number of scrambeled words and unscrambles them. I have already addressed the issues of partial matches, exits silently if there are no matches, and finds words regardless of case that they were input. but while trying to get it so... (3 Replies)
Discussion started by: alindner
3 Replies

7. Shell Programming and Scripting

Bash script issues

Hi. The below part of my bash script kicks out the following error message: $ ./extract_eod_report_stats_new.sh 2010-04-23 ./extract_eod_report_stats_new.sh: line 204: syntax error near unexpected token `(' ./extract_eod_report_stats_new.sh: line 204: `TRANSACTIONS_RECEIVED_TOP=`grep... (6 Replies)
Discussion started by: Peter.Lovell
6 Replies

8. UNIX for Dummies Questions & Answers

Basic Unix bash script help

Hello there Been using Unix bash scripting for two days now so am very new to this. I am currently doing a project now and i'm basically making a noughts and crosses game (or tic tac toe). I have created the board using an array. When I try and check to see if the array is empty using an If... (3 Replies)
Discussion started by: ChrisHoogie
3 Replies

9. UNIX for Dummies Questions & Answers

IP connection Bash script issues

Hello I need assistance with a bash script that needs to tell me whether in the last "x" days (which is a variable) anyone connected to the xxxx IP (which is another variable). Thank you! (1 Reply)
Discussion started by: Melchiah
1 Replies

10. Shell Programming and Scripting

UNIX script issues - Plse help guru's

Hi, I have written the following UNIX for HP-UX 11i. The script basically checks for files older then 45mins in 2 repective directories and then sends and email to the administrator about them. Problem with the script is that I can run it from the command line and crontabtab but 80% of the... (2 Replies)
Discussion started by: budrito
2 Replies
Login or Register to Ask a Question