简体   繁体   中英

cp: command not found

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 ??

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. 

In Linux, $PATH is an environmental variable that holds the directories to search for executable files (see for example http://www.linfo.org/path_env_var.html ).

I don't really know if your purpose is to change the PATH variable. If it is you should follow the konsolebox answer, but if not, you should avoid the use of environmental variables as variables in your script. Try using instead:

path=~/MkFile/

or

MYPATH=~/MkFile/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM