xiaonamylove 2020-10-16
问题重现:
当前系统Ubuntu16
shell进行字符串截取
运行 ${GIT_COMMIT:0:6}报错:
/tmp/jenkins7505855461406722507.sh: 4: /tmp/jenkins7505855461406722507.sh: Bad substitution
原因:两种shell语言解释器 bash和dash
查看当前/bin/sh 指向哪种解释器:
ls /bin/sh -al lrwxrwxrwx 1 root root 4 Mar 26 2018 /bin/sh -> dash
修改bin/sh指向为bash:
sudo ln -fs /bin/bash /bin/sh
或者运行 sudo dpkg-reconfigure dash
后选择NO
或者修改表达式 ${GIT_COMMIT:0:6}为:
$(echo $GIT_COMMIT | awk '{ string=substr($0,0,6); print string; }')