Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script Error: mv: invalid option --1

Posted on 2004-10-08
6
Medium Priority
?
745 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

688 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