Usage of mv in bash shell script

Discussion in 'Programming/Scripts' started by Yabadoo, Sep 30, 2006.

  1. Yabadoo

    Yabadoo Member

    Hello all,

    I want to use the mv command in a script named rename.sh, but when i run the command on the prompt (sh rename.sh) i have the error "mv: command not found". :confused: The script is in mode 0777.
    Below you will find the code i want to use.
    Any help is welcome !

    #!/bin/bash
    PATH="/var/opt/"

    #Rename before
    cd $PATH
    mv "file1.php" "file1.php.org"
    mv "file1.php.1" "file1.php"
    exit 0
    fi
     
  2. sjau

    sjau Local Meanie Moderator

    Try this:

    Code:
    #!/bin/bash
    PATH="/var/opt/";
    MV=/bin/mv;
    
    #Rename before
    cd $PATH
    MV "file1.php" "file1.php.org"
    MV "file1.php.1" "file1.php"
    exit 0
    fi
    
     
  3. Yabadoo

    Yabadoo Member

    I still have the same error "MV: command not found" ???
     
  4. sjau

    sjau Local Meanie Moderator

    then have a look where the binary for "mv" acutally is and adjust the path.
     
  5. Yabadoo

    Yabadoo Member

    I did a "locate mv", and the path where it is /bin/mv,
    exactly in the way it stands in the script....
     
  6. falko

    falko Super Moderator ISPConfig Developer

    Either use
    Code:
    #!/bin/bash
    PATH="/var/opt/";
    MV=/bin/mv;
    
    #Rename before
    cd $PATH
    [B][COLOR="Red"]$[/COLOR][/B]MV "file1.php" "file1.php.org"
    [B][COLOR="Red"]$[/COLOR][/B]MV "file1.php.1" "file1.php"
    exit 0
    fi
    
    or adjust the PATH variable in your original script:

    Code:
    #!/bin/bash
    PATH="[B][COLOR="Red"]/bin:[/COLOR][/B]/var/opt/"
    
    #Rename before
    [B][COLOR="Red"]cd /var/opt[/COLOR][/B]
    mv "file1.php" "file1.php.org"
    mv "file1.php.1" "file1.php"
    exit 0
    fi
     
  7. sjau

    sjau Local Meanie Moderator

    Stupid me, forgot to "$" ^^
     
  8. Yabadoo

    Yabadoo Member

    Thanks for the help Falko and Sjau !!!!.
    The $ did the trick, is runs perfect now.... :)
     

Share This Page