脚本执行到截取字符串时,报错提示:Bad substitution。 原因: 两种shell语言解释器 bash和dash,这种情况是指向了dash解释器导致。 解决方法: 1.查看shell指向:ls -l /bin/sh 2.修改脚本指向bash方法1:sudo dpkg-reconfigure dash然后选择no 修改脚本指向bash方法2:sudo rm -rf /bin/shsudo ln -s /bin/bash /b...
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; }')到此这篇关于shell字符串截取报错:Bad substitution的解决的⽂章就介绍到这了,更多相关shell字符串截取...
问题重现: 当前系统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 /bi...
Ubuntu shell 截取字符串时:bad substitution Code: #!/bin/bash b=`lsof -i:1080 | grep LISTEN` # echo ${b} if [ -z "${b}" ]; then echo "b is empty" else echo ${b:1:18} fi sh执行脚本 h2o2@ubt:~/文档/01-shell$ sh 01-命令输出.sh 01-命令输出.sh: 10: 01-命令输出....
当前系统Ubuntu16 shell进行字符串截取 运行${GIT_COMMIT:0:6}报错: /tmp/jenkins7505855461406722507.sh: 4: /tmp/jenkins7505855461406722507.sh: Bad substitution 原因:两种shell语言解释器 bash和dash 查看当前/bin/sh 指向哪种解释器: ls /bin/sh -al ...