Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cp: missing destination file operand after

Im trying to do a full back up and copy over all files from one directory into another directory

    #!/bin/bash 

    #getting files from this directory
    PROJECTDIRECTORY=/../../Project3 

    #Copied to this directory 
    FILEBACKUPLOCATION= /../.../FMonday

    for FILENAME in $PROJECTDIRECTORY/*
    do
        cp $FILENAME $FILEBACKUPLOCATION
        done  

But I keep getting this error

./fullbackup: line 6: /../../FMonday: Is a directory
cp: missing destination file operand after
like image 945
user3019469 Avatar asked Dec 02 '13 08:12

user3019469


1 Answers

Variable assignments in bash scripts require no space between the variable name and value or (unless quoted) within the value. Since a space was present in the line FILEBACKUPLOCATION= /../.../FMonday, it attempted to execute /../.../FMonday as a command (which caused the first error) with FILEBACKUPLOCATION assigned to an empty string. The variable was then not assigned when the other command further down tried to use it (accounting for the second error).

like image 195
user3019469 Avatar answered Sep 30 '22 12:09

user3019469