Linux下的shell命令执行set -ex 错误

shell脚本:

#!/bin/bash

set -ex

export GOPATH=/go
...()

执行命令报错:

$ ./build.sh
: invalid option 2: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
./build.sh: line 3: $'\r': command not found
./build.sh: line 5: $'\r': command not found
go: unknown environment setting GO111MODULE=on  

原因:
Linux下的shell命令执行set -ex 错误_第1张图片
格式错误:CRLF

解决方案:
修改为LF格式:
Linux下的shell命令执行set -ex 错误_第2张图片

你可能感兴趣的:(linux,运维,服务器)