Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1043383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:39:32+00:00 2026-05-16T15:39:32+00:00

I wrote a small shell script based on an example I found here: https://bbs.archlinux.org/viewtopic.php?id=36305

  • 0

I wrote a small shell script based on an example I found here: https://bbs.archlinux.org/viewtopic.php?id=36305

it takes this:

bash-3.2$ ls
test 001  test 002  test 003  test 004

and turns it into:

bash-3.2$ ls
001  002  003  004  rename.sh

However it gives me this error (even though it works):

bash-3.2$ ./rename.sh
mv: missing destination file operand after `rename.sh'
Try `mv --help' for more information.
`test 001' -> `001'
`test 002' -> `002'
`test 003' -> `003'
`test 004' -> `004'

Though it works correctly, it would be nice to see where I messed up, I assumed by default it would put the files in the same directory (this is the desired output).

#!/bin/bash
ls | while read -r FILE
do
        mv -v "$FILE" `echo $FILE | awk -F ' ' '{print $2}'`
done

Thanks in advance for helping me correct my incorrect code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:39:33+00:00Added an answer on May 16, 2026 at 3:39 pm

    Postman almost has it. For rename.sh, the awk command returns nothing so in effect you have the following command the shell attempts to execute:

    mv rename.sh
    

    hence the error message “missing destination file”

    you can fix this by testing for the filename of the script, either hardcoded or $0, and executing the mv command only if $FILE does equal the script name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small express.js based web app. I serve a manifest.webapp but express.js
I have a small shell script in a string inside my python file. Now
Can I set a small program that I wrote as my login shell? Instead
I'm currently trying to make some small shell-like utility for a custom script I
I am new to Shell script. Just have a small question about some script
I wrote a small script to help re-organize my .mp3 collection. When I run
I have shell scripting knowledge. I have written a small shell script which will
I wrote a very small application, which access the Remote Power Shell of Exchanger
I wrote two small applications (a client and a server) to test UDP communication
I wrote a small test program for flipperview. I have 3 views. I call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.