[root@coder-oldgeek]# sh deploy.sh
No such command: stop
Commands:
build Build or rebuild services
config Validate and view the Compose file
create Create services
down Stop and remove containers, networks, images, and volumes
events Receive real time events from containers
exec Execute a command in a running container
help Get help on a command
images List images
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pull service images
push Push service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show version information and quit
^CRemoves stopped service containers.
查看: sh文件内容
cat deploy.sh
#!/bin/bash
docker-compose stop
docker-compose rm -f
docker rmi oldgeek-springcloud-examples
docker build -t oldgeek-springcloud-examples .
docker-compose up -d
docker-compose ps
看sh内容,没啥问题
查看文件信息:file命令
[root@coder-oldgeek]# file deploy.sh
deploy.sh: Bourne-Again shell script, ASCII text executable, with CRLF line terminators
看上面信息【with CRLF line terminators】,大概能定位到问题
【注意点】在windows下编辑的shell脚本只看文件内容是没问题,但一旦到linux下可能就运行挂了
查找换行符号:find命令
find . -type f -name '*.sh' | xargs file |grep CRLF
替换换行符号
find . -name '*.sh' | xargs -I {} perl -pi -e 's/\r//g' {}
查看有问题文件是否去掉DOS格式下换行符号
[root@coder-oldgeek]# file deploy.sh
deploy.sh: Bourne-Again shell script, ASCII text executable
继续执行脚本deploy.sh,一切正常