第一个Shell脚本
2016-02-15 13:37
330 查看
编写脚本
作为解释器参数执行脚本
作为可执行程序执行脚本
[root@chen shell]# cat hello.sh #!/bin/bash echo "hello world!"“#!”是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行,即使用哪一种Shell。echo命令用于向窗口输出文本。
作为解释器参数执行脚本
[root@chen shell]# bash hello.sh hello world!直接运行解释器,其参数就是shell脚本的文件名,这种方式运行的脚本,不需要在第一行指定解释器信息,写了也没用。
作为可执行程序执行脚本
[root@chen shell]# chmod a+x hello.sh [root@chen shell]# ll 总用量 4 -rwxr-xr-x. 1 root root 32 1月 4 05:09 hello.sh [root@chen shell]# ./hello.sh hello world!注意,一定要写成./hello.sh,而不是hello.sh。运行其它二进制的程序也一样,直接写hello.sh,linux系统会去PATH里寻找有没有叫hello.sh的,而只有/bin, /sbin, /usr/bin,/usr/sbin等在PATH里,你的当前目录通常不在PATH里,所以写成hello.sh是会找不到命令的,要用./hello.sh告诉系统就在当前目录找。通过这种方式运行bash脚本,第一行一定要写对,好让Shell脚本查找到正确的解释器。
相关文章推荐
- Shell简介
- shell脚本之sed使用----替换、变量、转义字符
- adb shell 不支持Ctrl + C, TAB, DOWN/UP 等按键问题解决方案
- Linux ssh -bash: ulimit: 问题解决
- Linux运维初级教程(四)shell简介
- 小总结小展望
- ubuntu 开始ssh服务 使用xshell工具连接
- Shell expr的用法
- 使用DDMS查看安卓程序本地文件的内容
- shell升级完整记录
- shell升级
- LinuxShell Chapter1
- Linux shell编程中IO和条件及循环处理的细节问题讨论
- Linux系统中bash shell编程的10个基础问题讲解
- linux实战(三)----执行shell脚本----详细步骤讲解
- linux实战(三)----执行shell脚本----详细步骤讲解
- Use the Get-Command PowerShell Cmdlet to Find Parameter Set Information
- 开机自启动Powershell脚本
- Powershell 音乐播放
- Powershell指令集_2