shell脚本学习相关
2013-04-16 13:29
330 查看
1、bash: ./test.sh: 权限不够解决:
在linux下,自己编写的脚本需要执行的时候,需要加上执行的权限
解决方式:chmod 777 test.sh
2、bash: ./t.sh:/bin/bash^M:损坏的解释器: 没有那个文件或目录
出现类似的错误的原因是因为脚本在windows下编辑过;在windows下,每一行的结尾实际上是\n\r,而在linux下,文件的结尾是\n,则在windows下编辑过的文件在linux下打开看的时候,每一行都会多出来一个字符,用cat -A test.sh查看,可知\r字符被显示为^M,
#!/bin/bash^M$
#filename:change_file_name.sh^M$
^M$
for avifile in *.avi^M$
do ^M$
^Iecho "the old name is $avifile and we change the old name "^M$
^Iecho "we get the avifile name"^M$
^Iaviname=${avifile%.*}^M$
^IoldIFS=$IFS^M$
^IIFS=-^M$
^Ifor item in $aviname^M$
^Ido^M$
^I^Iecho item:$item^M$
^Idone^M$
done^M$
这时候只要删除这个字符就可以了,sed -i 's/\r$//' test.sh
3、错误类型:期待一元表达式
我自己的错误是将eq左右的表达式写错了
4、
在linux下,自己编写的脚本需要执行的时候,需要加上执行的权限
解决方式:chmod 777 test.sh
2、bash: ./t.sh:/bin/bash^M:损坏的解释器: 没有那个文件或目录
出现类似的错误的原因是因为脚本在windows下编辑过;在windows下,每一行的结尾实际上是\n\r,而在linux下,文件的结尾是\n,则在windows下编辑过的文件在linux下打开看的时候,每一行都会多出来一个字符,用cat -A test.sh查看,可知\r字符被显示为^M,
#!/bin/bash^M$
#filename:change_file_name.sh^M$
^M$
for avifile in *.avi^M$
do ^M$
^Iecho "the old name is $avifile and we change the old name "^M$
^Iecho "we get the avifile name"^M$
^Iaviname=${avifile%.*}^M$
^IoldIFS=$IFS^M$
^IIFS=-^M$
^Ifor item in $aviname^M$
^Ido^M$
^I^Iecho item:$item^M$
^Idone^M$
done^M$
这时候只要删除这个字符就可以了,sed -i 's/\r$//' test.sh
3、错误类型:期待一元表达式
我自己的错误是将eq左右的表达式写错了
4、
相关文章推荐
- linux学习笔记:shell脚本编程相关(上)
- hadoop相关启动脚本分析 有助于troubleshoot,顺便学习shell
- Shell 脚本基础学习 (二)
- Shell脚本学习笔记(二)--变量
- shell脚本学习01
- Liunx 命令行与shell脚本编程大全 第五章学习笔记(Vim 编辑器使用详解 解释+图示)
- Shell脚本学习之基本参数
- Shell脚本学习指南(三)——正则表达式
- linux及shell相关学习
- 鸟书shell学习(三)shell脚本程序设计要点总结
- shell脚本学习入门
- Linux学习-shell脚本编程基础(节选)
- Android build(6) -- shell脚本的学习
- shell脚本学习知识总结
- Linux学习-shell脚本编程基础之处理用户输入
- NO3.Shell脚本学习——编写Shell脚本
- 关于shell脚本学习
- Shell脚本编程学习入门 02 分类: arm-linux-Ubuntu 2013-08-30 17:45 427人阅读 评论(0) 收藏
- [shell脚本学习]处理用户输入
- Shell 脚本专家指南 学习笔记3 目录的复制