shell字符串截取报错:Bad substitution的解决
问题重现:
当前系统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; }')
相关推荐
liguojia 2020-10-20
woaimeinuo 2020-10-21
tianhuak 2020-11-24
huha 2020-10-16
lianshaohua 2020-09-23
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
彼岸随笔 2020-10-20
lianshaohua 2020-10-20
yutou0 2020-10-17
JohnYork 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
ourtimes 2020-10-16