cp: command not found

20,173

Solution 1

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.

Solution 2

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/

Share:
20,173
Admin
Author by

Admin

Updated on March 09, 2020

Comments

  • Admin
    Admin over 4 years

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