Error: `mv olddir/ newdir/ ` never works on new version of bash?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Error: `mv olddir/ newdir/ ` never works on new version of bash?
# 1  
Old 02-20-2008
Error: `mv olddir/ newdir/ ` never works on new version of bash?

Suppose you have a directory called "olddir" exists but no "newdir", you want to rename "olddir" to"newdir"
In previous versions (at least in 2.05b.0) of bash, you can try
mv olddir/ newdir/
OR
mv olddir/ newdir

But in new versions of bash, if you
mv olddir/ newdir/
BASH panics:
mv: target `newdir/' is not a directory: No such file or directory

Anybody notices this?
# 2  
Old 02-20-2008
I don't think the problem is the bash version:

Code:
test ~ $ bash --version
GNU bash, version 3.2.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
test ~ $ mkdir olddir
test ~ $ mv olddir/ newdir/
test ~ $

On Linux both syntaxes works for me.
# 3  
Old 02-20-2008
Thank you. Here are all the info:

$ ls
drwxr-xr-x 2 root root 4096 2008-02-20 12:03 olddir

$ mv olddir/ newdir/
mv: target `newdir/' is not a directory: No such file or directory

$ which mv
/bin/mv

$ bash --version
GNU bash, version 3.2.13(1)-release (i486-pc-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
# 4  
Old 02-20-2008
This is flawed syntax for what you are trying to do:
mv olddir/ newdir/

The above command is explicitly saying: "Take the olddir directory and move it into the newdir directory". If newdir does not exist or olddir is a file, it _should_ fail.

Intersting that it works sometimes...
# 5  
Old 02-20-2008
Quote:
Originally Posted by Smiling Dragon
This is flawed syntax for what you are trying to do:
mv olddir/ newdir/

The above command is explicitly saying: "Take the olddir directory and move it into the newdir directory". If newdir does not exist or olddir is a file, it _should_ fail.

Intersting that it works sometimes...
Thanks, but how to explain why it works with somebody's bash ?
BTW the exact syntax works with my another machine, which has bash version:

$ bash --version
GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu)
Copyright (C) 2002 Free Software Foundation, Inc.
# 6  
Old 02-20-2008
Some guesses might be the path order and different mv commands, or an alias (dont forget which -a)

mv old/ new/ is trying to put old into new not rename old as new. You coild have some globbing by default with one shell and not the other that would address this.

Like that man said above, this is working as intended.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Command works interactively but not in bash script

The below command works in the terminal interactively but not as part of a bash script. I though maybe I needed to escape the "$dir" so it isn't interpreted literally, but that's not it. Thank you :). interactively in terminal dir=/path/to new=$(ls "$dir"/*.csv -tr | tail -n 1) && echo... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

Script in bash that works only some of the time

I ran this script yesterday (in the background) /usr/bin/nohup myfilelocation/myscriptname.sh & the script worked perfectly. i ran it today (also in the background) and just sat there. So i killed it and ran it normally and it worked perfectly. Anyone suggest why it just sat there and... (8 Replies)
Discussion started by: twinion
8 Replies

3. Shell Programming and Scripting

Sourcing Env file with eval works with ksh but not BASH

Hi, I am running this on Redhat 5.10 I have a simple test script called test.sh which has the following contents and it uses the BASH shebang. ------------------------------------------------------------- #!/bin/bash eval `/tmp/filereader.pl /tmp/envfile.txt` echo "TESTPATH=$TESTPATH" ... (28 Replies)
Discussion started by: waavman
28 Replies

4. Shell Programming and Scripting

Calling bash script works when called manually but not via Cron?

Hi, I've got a Bash backup script I'm trying to run on a directory via a cron job nightly. If I ssh in and run the script manually it works flawlessly. If I set up the cron to run evertything is totally messed up I don't even know where to begin. Basically the path structure is ... (6 Replies)
Discussion started by: wyclef
6 Replies

5. UNIX for Dummies Questions & Answers

Bash script dont works when executed as cronjob

Hello, i have cronjob: crontab -l * * * * * pkill -f domexpcheck;sh /root/dom/domexpcheck.sh it runs: /var/log/cron Mar 25 12:11:01 vps crond: (root) CMD (pkill -f domexpcheck;sh /root/dom/domexpcheck.sh) but somehow script dont run properly via cronjob. But when i execute cronjob... (7 Replies)
Discussion started by: postcd
7 Replies

6. Shell Programming and Scripting

Script works with bash 3.0 but not 3.2.

Hello, So my knowledge of bash scripting is not that great and I have been trying to solve this problem on my own for awhile to no avail. Here's the error I get when running it with an OS that uses bash 3.2.x: testagain.sh: line 10: *-1: syntax error: operand expected (error token is... (2 Replies)
Discussion started by: forkandspoon
2 Replies

7. Shell Programming and Scripting

bash version or string issue

Hi all, I'm not sure but I guess, that is a bash version issue. The script working fine on "GNU bash, version 3.2.25(1)-release Ubuntu". #!/bin/bash while IFS=">" read a id val do if ] then VAL=${id%<*}; ID=${id#*</} echo $VAL echo $ID sed... (5 Replies)
Discussion started by: research3
5 Replies

8. Solaris

how to upgrade bash's version ?

Dear all, How to upgrade bash's version? which way should be easy between remove the old version first and upgrade it or upgrade without remove? Please, tell me how to upgrade step by step because I'm newbie thank in advance (4 Replies)
Discussion started by: unitipon
4 Replies

9. Shell Programming and Scripting

Works from bash prompt, but not from script!

I'm trying to use unison from bash on windows with cygwin. I don't know if this is a cygwin question, bash question or unison question. Since I always get reprimanded by the cygwin mailing list for assuming it is a cygwin problem, I'll assume it is a bash question. The following commands work... (7 Replies)
Discussion started by: siegfried
7 Replies

10. Shell Programming and Scripting

substring command works but only in BASH shell

I am having trouble running a .sh file. The code 'x=${file_name:0:$z-11}' is giving me a bad substitution error. However when I run in BASH it works. Thing is when this goes to production the .sh will not be running in BASH. Is there a way to substring a string not in BASH or a way to invoke... (2 Replies)
Discussion started by: edwardtk11
2 Replies
Login or Register to Ask a Question