[英]cp: command not found
我試圖將一個文件復制到其他目錄,並在調用中斷時收到錯誤消息。
劇本 :
#!/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
輸出:
./signal.sh
What? ^C
Called ctrl + c
./signal.sh: line 9: cp: command not found
您知道此腳本有什么問題嗎?
您修改了PATH變量,這就是原因。 也許您只想添加另一條路徑:
PATH=$PATH:~/MkFile/
或者,如果在Bash
,只需使用append運算符:
PATH+=:~/MkFile/
想到這一點,我不認為您實際上要使用PATH變量。 只需使用另一個參數名稱即可:
DIR=~/MkFile/
有人建議僅使用小寫字母以避免與內置的shell變量沖突:
path=~/MkFile/
從手冊中:
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.
在Linux中,$ PATH是一個環境變量,其中包含用於搜索可執行文件的目錄(例如,參見http://www.linfo.org/path_env_var.html )。
我真的不知道您的目的是否是要更改PATH變量。 如果是,則應遵循konsolebox的答案,否則,應避免在腳本中使用環境變量作為變量。 嘗試改用:
路徑=〜/ MkFile /
要么
MYPATH =〜/ MkFile /
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.