cp: command not found

VIJAY GUPTA picture VIJAY GUPTA · Aug 13, 2014 · Viewed 17.3k times · Source

I am trying to copy one file to other directory and getting error message while interrupt is called.

The Script :

#!/bin/bash


PATH=~/MkFile/

exitfn () {
    trap SIGINT              # Resore signal handling for SIGINT
        echo ; echo 'Called ctrl + c '    # Growl at user,

        cp ./BKP/temp.txt $PATH/backup.txt
            exit                     #   then exit script.
}

trap "exitfn" INT            # Set up SIGINT trap to call function.ii



    read -p "What? "

    echo "You said: $REPLY"
# reset all traps## 


    trap - 0 SIGINT

Output :

./signal.sh
What? ^C
Called ctrl + c
./signal.sh: line 9: cp: command not found

Do you have idea what is wrong in this script ??

Answer

konsolebox picture konsolebox · Aug 13, 2014

You modified your PATH variable that's why. Perhaps you just want to add another path to it:

PATH=$PATH:~/MkFile/

Or if in Bash, simply use the append operator:

PATH+=:~/MkFile/

Come to think of it, I don't think you actually want to use the PATH variable. Just use another parameter name instead:

DIR=~/MkFile/

And some would recommend just using lowercase letters to avoid conflict with builtin shell variables:

path=~/MkFile/

From the manual:

PATH    A colon-separated list of directories in which the shell looks for
        commands.  A zero-length (null) directory name in the value of PATH
        indicates the current directory. A null directory name may appear
        as two adjacent colons, or as an initial or trailing colon.