$'\r': command not found

描述:

今天在执行一个shell脚本时报错line 3: $’\r’: command not found

[admin@A01-R15-I38-71-6001995 bin]$ sh -x generate-supervisor-conf.sh 
+++ dirname generate-supervisor-conf.sh
++ cd .
++ pwd
+ BIN_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin
+ INST_ROOT_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/..
+ . /export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/utils/color-utils.sh
+ . /export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/acc-common-def.sh
++ ACC_CONFIG_NAME=acc.conf.base
++ ACC_BINARY_FILE_NAME=access_control_center
++ GEN_CONF_ROOT_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/..
++ GEN_CONF_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf
++ GEN_ACC_CONF_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/acc
++ GEN_SUPERVISOR_CONF_FILE_PATH=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/acc-supervisor.conf
++ GEN_SUPERVISOR_CHILDREN_CONF_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/supervisor-children
+ INST_CONF_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf
+ INST_ACC_CONF_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/acc
+ INST_SUPERVISOR_CHILDREN_CONF_DIR=/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/supervisor-children
+ /export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/generate-directly-startup-conf.sh /export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/acc /export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/acc-biz.json
/export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/acc.conf.base: line 3: $'\r': command not found
generate config /export/Instances/access-control-center-jss-paas/10.access-control-center-jss-paas/runtime/bin/../conf/acc/acc9905.conf
问题解决
  • 查看acc.conf.base文件第三行发现是空行,也就是里面肯定有换行符,假设这个文件是在Windows下编辑的,那么Windows下换行符是\r\n,unix下是\n, 所以这里就多了个r,所以执行脚本是就报找不到这个命令,网上给的解决方式是dos2unix 脚本名称,亲测这个方法不好用
  • vim acc.conf.base,然后执行:set fileformat=unix,然后wq,在次执行脚本报错消失

你可能感兴趣的:(运维常见问题)