求解CP的时候报错!请问该怎么修改?

shell如下:#!/bin/bash
echo $1
echo $1
MY_TOMCAT='/home/was/test/tomcat'
PROJECT_NAME='dqmhsm'
WAR=$1
echo $MY_TOMCAT
echo $PROJECT_NAME
#dep webapps
dep_project(){
echo "dep project start!"
if [ -n "$MY_TOMCAT" ];then
PID=`ps -ef|grep $MY_TOMCAT |grep -v 'grep' | awk '{print $2}'`
if [ -n "$PID" ];then 
echo kill process $PID
for i in $PID
do 
kill -9 $i
done
else echo process had stopped!
fi
sleep 5
#echo rm -rf $MY_TOMCAT/webapps/$PROJECT_NAME/*
rm -rf $MY_TOMCAT/webapps/$PROJECT_NAME/*&&echo delete file success!
echo cp $WAR $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR
cp $1 $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR
cd $MY_TOMCAT/webapps/$PROJECT_NAME/
jar -vxf $WAR
#rm -rf $WAR
sh $MY_TOMCAT/bin/startup.sh
sleep 5
tail -f $MY_TOMCAT/logs/catalina.out
else echo tomcat path is null
fi
}
if [ -n "$WAR" ];then
dep_project;
else 
echo "dep war is null"
fi

运行结果:
[was@wtjs38 test]$ ./dep.sh test.war 
test.war
test.war
/home/was/test/tomcat
dqmhsm
dep project start!
process had stopped!
delete file success!
cp test.war /home/was/test/tomcat/webapps/dqmhsm/test.war
cp: missing destination file operand after “/home/was/test/tomcat/webapps/dqmhsm/test.war”

慕神8447489
浏览 150回答 2
2回答

慕哥6287543

把shell里面的cp test.war /home/was/test/tomcat/webapps/dqmhsm/test.war改成cp test.war /home/was/test/tomcat/webapps/dqmhsm/

慕村225694

#echo rm -rf $MY_TOMCAT/webapps/$PROJECT_NAME/*  rm -rf $MY_TOMCAT/webapps/$PROJECT_NAME/*&&echo delete file success!  echo cp $WAR $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR  cp $1 $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR  请注意,这几句是在函数 “dep_project()”里面的,而函数里面的位置变量是在调用函数时传入的。并不和脚本运行时的一致。上例中调用“dep_project”并没有传入参数。所以在函数中"$1"是空值。可以将  cp $1 $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR  改为cp $WAR $MY_TOMCAT/webapps/$PROJECT_NAME/$WAR或将:  dep_project;  改为dep_project $WAR;  。
打开App,查看更多内容
随时随地看视频慕课网APP