我想知道爲什麼在我的shellcript下面寫下「not found」錯誤,所以請告訴我我在代碼中的錯誤(環境:mac OS X和CentOS6)ls和grep命令「找不到」shellcript中的錯誤
「xaf.sh」
#!/bin/sh
SERVER=$1
USER=$2
PASS=$3
FILE=$4
PATH=$5
echo $1
VAR=`ls | grep ${FILE}`
for one_file in ${VAR}; do
echo $one_file
echo "go"
touch ./ftp_err/log
ftp -nv 2>./ftp_err.log <<END
open $SERVER
user $USER $PASS
cd /$PATH
binary
prompt
put ${one_file}
exit
END
VAR2=`wc ./ftp_err.log`
if [VAR2 -gt 0 ] ; then
echo "you have an error in sending ${one_file}"
else
echo "you have succeeded Transfer of ${one_file}"
rm ${one_file}
fi
rm ./ftp_err.log
done
...並命令我如何發出和執行的結果如下(用戶名和密碼的部分被替代#)
**Command**
./xaf.sh 192.168.202.171 #r#####er c#####b## 2 /tmp/
**Result**
./xaf.sh: line 9: ls: command not found
./xaf.sh: line 9: grep: command not found
我成功使用LS,grep的代碼,併爲如下 #!/ bin/sh的寫在 回聲$ 1 FILE = $ 1 VAR ='LS |對於$ {VAR}中的one_file,grep $ {FILE}' ;做 echo $ one_file echo「go」 done –
這是什麼目的:''VAR ='ls | grep $ {FILE}'''?改爲使用:'for *中的one_file $ file「*;做...' –