DBDevOne
asked on
Script Error: mv: invalid option --1
The script changes the extention on file names. It is as follows:
for i in 'ls *.aaa | cut -f1 -d '; do
mv $i.aaa $i.bbb;
done
getting an error when run
mv: invalid option --1
for i in 'ls *.aaa | cut -f1 -d '; do
mv $i.aaa $i.bbb;
done
getting an error when run
mv: invalid option --1
ASKER
Thanks for teh comment. This is my first script. There are no spaces or multiple extentions. How would I modify my script to eliminate the error?
A better way would be:
for f in *.aaa; do
mv $f `basename $f .aaa`.bbb
done
for f in *.aaa; do
mv $f `basename $f .aaa`.bbb
done
ASKER
What is basename? Can you list and example?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your answers. Brett, I am sure yours was great too, I chose jlevie's because it helped me find the cause of the error I got.
Your script will also fail if a filename contains spaces or multiple
filename extensions.
I recently wrote this script for a client that was transitioning from
Linux to Mac OS X (which lacks the Linux 'rename' command):
#!/bin/bash
# This Bash shell script emulates the linux 'rename (1)' command
# The "usage" man page help was shamelessly stolen from Linux.
# 04 Aug 2004 Brett Johnson
# Must have at least three args: fromtext, totext, file...
if [ $# -lt 3 ] ; then
cat <<END
NAME
rename - bulk rename files
SYNOPSIS
rename fromtext totext files...
DESCRIPTION
rename will rename the specified files by replacing the
first occurrence of fromtext in their name with totext.
For example, given the files foo1, ..., foo9, foo10, ..., foo278,
the commands
rename foo foo0 foo?
rename foo foo0 foo??
will turn them into foo001, ..., foo009, foo010, ..., foo278.
And
rename .htm .html *.htm
will fix the extension of your html files.
END
else
fromtext=$1
totext=$2
shift 2
for f in "$@" ; do mv $f ${f/$fromtext/$totext} ; done
fi