1 入门实例及解释
| #! /bin/sh cd /home echo "hello" |
dos编写的hello.sh 直接丢到linux服务器 可能不能执行!
-bash: ./hello.sh: /bin/sh^M: bad interpreter: No such file or directory!
问题的原因是我在windows下编辑然后上传到linux系统里执行的。
.sh文件的格式为dos格式。而linux只能执行格式为unix格式的脚本
yum install dos2unix
安装完成进行格式转换:dos2unix hello.sh
dos2unix: converting file hello.sh to Unix format ...
再执行就可以了!



2 活用其他命令解释器
| 每个脚本的头都指定了一个不同的命令解析器! 如:自删除脚本 #! /bin/rm 如:自展示文本 #! /bin/more 可以使用whereis 命令查询解释器的完整路径 ![]() |
3 查看系统支持的shell
cat /etc/shells
|
4 执行shell脚本的三种方式
同样的脚本:如果方式1 2 选用的shell解释器相同,那么结果相同! 但是,跟方式3的结果却不同! |
5 shell命令的种类:大致可以分为三类
![]() ![]() ![]() ![]() |










被折叠的 条评论
为什么被折叠?



