Blog:博客园 个人 译自BashPitfalls 本文总结了编写Shell脚本中的常见错误. for f in $(ls *.mp3) 最常犯的错之一就是编写这样的循环: for f in $(ls *.mp3); do # Wrong! some command $f # Wrong! done for f in $(ls) # Wrong! for f in `ls` # Wrong! for f in $(find . -type f) # Wrong! for f in `find
启动hbase之后,发现hbase shell启动报错: version 2.0.0-alpha4, r5c4b985f89c99cc8b0f8515a4097c811a0848835, Tue Oct 31 16:00:33 PDT 2017[ERROR] Terminal initialization failed; falling back to unsupportedjava.lang.IncompatibleClassChangeError: Found class jline.Ter
今天写了个shell脚本,在自己机器上运行正常,给同事,运行报错syntax error near unexpected token `,左看右看shell脚本没有问题,没有办法google搜索,发现一位仁兄讲的挺好,内容如下: 用命令vi -b 打开你的SHELL脚本文件,你会.发现每行脚本最后多了个^M. 那么接下来就要搞清楚这个^M是什么东东? long long ago..... 老式的电传打字机使用两个字符来另起新行.一个字符把滑动架移回首位 (称为回车,<CR>,ASCII码为0
此错误是shell脚本在计算以0开头的数字时,默认以8进制进行计算,导致在计算08时超过了8进制的范围,报此错误. shell脚本代码如下: #!/bin/bash a= ..} do a=$[$a+] ] then a="$a fi echo "$a" done 运行之后的结果: t.sh: line : : value too great ") 解决方法:使用10#将该变量声明为10进制. 如下代码即可成功运行. a= ..} do a=$[] ] then a
shell 执行报错: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory 原因:window和linux 的文件格式不同,这个问题是:linux换行只需要 /n windows的换行是 /r/n 导致文件不能识别. vim 查看文件格式: set ff? fileformat=dos 就是window 的文件格式 修改: set fileformat=unix 搞定