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 9215481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:12:50+00:00 2026-06-18T02:12:50+00:00

I have a wrapper script called my_mv.sh like below(I am using bash): #/bin/bash function

  • 0

I have a wrapper script called my_mv.sh like below(I am using bash):

#/bin/bash
function my_mv(){   
FILE="${@: -1}" # bash or ksh,zsh 
echo $FILE
if [ -f $FILE ];   
then   
    mv -i $@                                                                                                                                                                     
else   
    mv $@   
fi   
}   

When I use it as a script and run it directly like ./my_mv.sh file1 file2, the result is as expected. However when I put function my_mv into ~/.bashrc and source it, there would be a infinite loop.
So what’s the difference between the two methods? How can I change the script so it can be sourced right?

BTW, when using zsh, there is a similar result for the two approaches.

  • 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-06-18T02:12:52+00:00Added an answer on June 18, 2026 at 2:12 am

    Did you actually name it my_mv in your .bashrc, or did you in fact name it mv, to override the default?

    If so, use command mv instead of just mv in your function to invoke the system version instead of recursing.

    If you just run this as ./my_mv.sh file1 file2, it will not do anything, because the function is defined but not called.

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

Sidebar

Related Questions

Scenario 1: I have one wrapper Perl script which uses another Perl module and
Essentially I have a script which acts as a task wrapper and emails a
I'm using an OpenLayers wrapper for GWT, called GWT-OpenLayers On user reference page it
I have a Header File by the name header.php which goes like this :
The user launchs a script called wrapper.ps1 It has param( [string]$command, [string]$item='' etc )
I have created a wrapper which can execute a given script over SSH with
I'm using a script called autobrowse It represents an infinite scroll type of script
Context: I have a bash script that contains a subshell and a trap for
I have a wrapper python script which repeatedly calls another python script via os.system
Problem We have a DBA provided wrapper script that is used to execute a

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.