Solved

Script Error: mv: invalid option --1

Posted on 2004-10-08
6
702 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:DBDevOne
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12261430
Your cut command delimiter is wrong.  I think you wanted -d .
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
0
 

Author Comment

by:DBDevOne
ID: 12261550
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?
0
 
LVL 40

Expert Comment

by:jlevie
ID: 12261641
A better way would be:

for f in *.aaa; do
  mv $f `basename $f .aaa`.bbb
done
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DBDevOne
ID: 12261767
What is basename? Can you list and example?
0
 
LVL 40

Accepted Solution

by:
jlevie earned 500 total points
ID: 12262058
From 'man basename':

basename - strip directory and suffix from filenames

DESCRIPTION
       Print  NAME  with  any leading directory components removed.  If speci-
       fied, also remove a trailing SUFFIX.

My example uses its ability to strip a specified SUFFIX (.aaa) from a file name. By executing the command in a subshell `basename $f .aaa` I get the portion of the filename up to the suffix returned to which I append .bbb. So `basename this-is-the-file.aaa .aaa` would return this-is-the-file and
`basename this-is-the-file.aaa .aaa`.bbb would yield this-is-the-file.bbb.

Make sense?
0
 

Author Comment

by:DBDevOne
ID: 12267100
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question