使用pycharm编写shell脚本,又使用deployment功能上传linux服务器的时候,运行发现报错,仔细检查以后才发现是windows回车符问题,使用 vim -b [文件] 可以看到每一行后面多了一个^M
#!/bin/bash^M
dir=$(ls)^M
for i in $dir^M
do^M
if [ -d $i ]^M
then^M
echo "$i是一个目录"^M
cd $i^M
if [ -f install.sh ]^M
then^M
echo "install.sh 存在"^M
^M
count=$(grep -c dev_ install.sh)^M
if [ $count -eq 1 ]^M
then^M
echo "dev_数量等于1"^M
sh install.sh dev # 有dev参数的话,执行脚
本加dev参数^M
else^M
echo "没有找到dev_"^M
fi^M
^M
cd ..^M
else^M
echo "install.sh 不存在"^M
cd ..^M
这样在linux下运行脚本会报格式错误等等,这样设置一下pycharm再使用deployment功能上传就好啦
解决办法
1、选中项目根节点
2、File --> Line Separators --> LF Unix